Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: dispatch system #1685

Merged
merged 55 commits into from
Oct 18, 2023
Merged

refactor: dispatch system #1685

merged 55 commits into from
Oct 18, 2023

Conversation

mehah
Copy link
Contributor

@mehah mehah commented Oct 6, 2023

Dispatch has been refactored to be centralized in just one thread. Previously, each task was sent to the threads that were free, which could cause bottlenecks because they were stuck with mutexes, causing queues depending on how many threads the cpu had.

small illustration of a possible problem:
image

Apart from what was mentioned above,, the scheduling class has been removed and we now have new methods in dispatch, addEvent_async, scheduleEvent and cycleEvent.

Note

  • addEvent_async(func, context_id)
    • With this method it is now possible to create an asynchronous event that will be executed before all synchronous events.

Questions

  • Why Scoped Object
    • there is a big cost in allocating(new) and deallocating(delete) an object from memory and since we don't need to manage the lifetime of the object or share it, it doesn't make sense to use smart pointer.

Benchmark

  • Scoped Object vs Smart Pointer
    image
struct Teste {
	int i;
};

Benchmark bm;
for (uint_fast32_t i = 0; i < 999; ++i) {
	std::vector<Teste> list;
	for (uint_fast32_t d = 0; d < 99999; ++d) {
		list.emplace_back(d);
	}
	list.clear();
}

g_logger().info("Scoped Object {}ms", bm.duration());

bm.reset();
bm.start();

for (uint_fast32_t i = 0; i < 999; ++i) {
	std::vector<std::unique_ptr<Teste>> list;
	for (uint_fast32_t d = 0; d < 99999; ++d) {
		list.emplace_back(std::make_unique<Teste>(d));
	}
	list.clear();
}

g_logger().info("Smart Pointer {}ms", bm.duration());
```</details>

@mehah mehah marked this pull request as draft October 6, 2023 20:28
@mehah mehah marked this pull request as ready for review October 7, 2023 01:46
mehah added 7 commits October 7, 2023 12:38
commit ae2b608
Author: Renato Machado <[email protected]>
Date:   Wed Oct 11 20:39:37 2023 -0300

    improve

commit 33163d6
Author: Renato Machado <[email protected]>
Date:   Wed Oct 11 19:07:51 2023 -0300

    rework updateTargetList loop

commit e4320e1
Author: Renato Machado <[email protected]>
Date:   Wed Oct 11 18:58:28 2023 -0300

    fix crash on updateTargetList

commit 73827db
Author: Renato Machado <[email protected]>
Date:   Wed Oct 11 18:30:21 2023 -0300

    Async Event Context / Cleanup

commit d56e191
Author: Renato Machado <[email protected]>
Date:   Wed Oct 11 16:16:01 2023 -0300

    addEvent_async

commit 3e162ca
Author: Renato Machado <[email protected]>
Date:   Wed Oct 11 15:30:41 2023 -0300

    rework
src/game/scheduling/dispatcher.cpp Outdated Show resolved Hide resolved
src/game/scheduling/dispatcher.cpp Outdated Show resolved Hide resolved
src/game/scheduling/dispatcher.cpp Outdated Show resolved Hide resolved
src/game/scheduling/dispatcher.cpp Outdated Show resolved Hide resolved
src/game/scheduling/task.hpp Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 14 Code Smells

0.0% 0.0% Coverage
0.3% 0.3% Duplication

@luan luan merged commit fb5f3ca into main Oct 18, 2023
30 checks passed
@luan luan deleted the new-dispatch branch October 18, 2023 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants