Comments (9)
Of course. I was copying back into the temporal array every time i wanted to update the system. Even with the copy and allocation it was still a big upgrade in performance. This would be pointless and you would lose performance if the complexity of each iteration is low.
from entt.
The whole entity-component system isn't thread safe out of the box. The README file already contains some notes about it.
Adding mutexes or whatever all around the codebase would ruin the performance in case you use it in single threaded applications, applications based on async stuff or if you have a go with the classical threading model of an ECS.
So, no need for a line to each function description in the documentation. It would be redundant.
If you care about it, I can add a dedicated section to the README where I mention it explicitly once and for all the cases.
from entt.
Yes, please. Do add a section specifically about thread safety.
from entt.
Not a problem. Maybe it's better if I add an extensive note to the Side Notes section. It already tells something to the readers about thread safety and views actually. There isn't much to say about this argument, but for the fact that I could write a book about how to deal with threads in an ECS!! :-)
from entt.
Added a note as mentioned above. Thank you for having pointed it out.
from entt.
Thanks for adding the note. Two comments, however:
- It's better to put it in named section, which has a link in the Table of Contents. That way, it's obvious from the TOC that there's a section devoted to this topic. It's an important topic. Currently, it's burried in the side notes, so it's not apparent that it's mentioned in the docs. Even knowing that you added it, I couldn't find it, at first, and had to look at the commit history.
- I mean no offense, but the info that you added isn't very useful. It's mostly justification, or telling the users what they need or want. Instead, it should state facts, and let the users make their own choices based on those facts. People know what they need. Maybe something along the lines of:
"The EnTT framework uses no locks or other synchronization primitives. As such, it requires external synchronization for [most|all] calls when used in a multi-threaded environment.
"Such and such methods are thread safe.
"Such and such methods may be called without external synchronization, as long as this and that requirements are met. Otherwise, they must be externally synchronized.
"Such and such methods must always be externally synchronized.
"Such and such methods must not be called from multiple threads because they use global or static data."
Thanks
from entt.
No offense, don't worry. I see what you say.
The problem is that it's much more complicated than this. It's not just a list like such and such ok, such and such no.
First of all, one should have a grasp of what are the possible approaches to the problem ECS and threads. Then I should explain in which cases a solution should be preferred and why. At this point we can explore the methods one at a time and say something about them for the particular solution, even though it's still different from the such and such description.
There are methods that are thread safe if and only if you did something before. As an example, the view
member function template, is it thread safe? It depends. Did you know it?
These are consequences of some choices made in the past that gave you today a runtime tool that is faster than its compile-time counterparts and has a nicer API.
Well, this isn't for free. It has a buried complexity that makes it difficult to fully understand how it works and explain it in a few lines.
I was not joking when I said that I should write a book about thread safety and EnTT. Actually, more in general, about ECS and pick your argument, using EnTT as an example.
Unfortunately I'm doing all of this in my free time and I cannot provide users with a full explanation about thread based models for ECS, plus a detailed description of how to use EnTT and squeeze the best out of it in such a context.
That's also why I'm available for hiring. ;-)
Consider that part of the features you enjoy are the result of funded development or donations.
There had been only one (actually very big and well known) game company that invited me to the headquarter to know more about EnTT, wrote down all the information and hadn't even reimbursed the flight: no comment.
To be honest, I'm sorry if you don't get a full answer on the topic at the end of the discussion.
EnTT can be easily and freely used in a multi thread application (either a game or whatever). However, doing this requires quite a good grasp of its internals and it's far behond the goal of the README (that is already indecently large).
Probably I should open an account on patreon or write the above mentioned notes/book somehow, somewhere.
This is the first time someone asked me explicitly to do that. Let's see if some others follow you and thus doing it is worth it. ;-)
from entt.
Probably should write about what i did.
In the space battle i created, the target aquisition for the bullets was too expensive. Even with an acceleration structure, there were 3000 bullets trying to find all of the possible targets in an X radius to steer towards them.
What i did, is to use a raw view .count function to initialize an array, and then a normal view to copy all the bullet data from the view into that array (by storing pointers to the components).
After the copy was done, i did a Parallel For (given by unreal engine, does exactly what it sounds like, #pragma omp parallel for would do too) to iterate through that copy and do my logic. As i was storing pointers to the components, they were updated well.
I did not try to have multiple views iterating at the same time, as that would prove complex to check. A parallel for is dirt simple. and gave me a x5 speedup (on a ryzen) on the code i needed to speed up.
from entt.
As i was storing pointers to the components, they were updated well.
Be aware that pointers and references to components can be invalidated in case you add or remove some other instances.
from entt.
Related Issues (20)
- registry.create() returning entt::entity of id greater than entt::null? HOT 2
- Get variable from meta_any by reference instead of copy? HOT 2
- std::allocator deprecated in C++17 HOT 10
- Signals for inherited registry HOT 2
- nvcc 'incomplete type is not allowed' compile error HOT 6
- "EnTTish" way to "get children" of parent? HOT 4
- Is there a way to retrieve a view with at least one of the specified components? HOT 4
- Possible reasons for crashing at "slot not available"? HOT 5
- Incorrect void type check in registry's assure function HOT 1
- Unable to use std::ranges::is_sorted with view's each - not a forward iterator HOT 8
- Support for failure in basic_snapshot_loader and entt::snapshot HOT 12
- One meta c++ class, many meta_type HOT 3
- basic_sparse_set - assure_at_least Assertion `elem == null' failed. HOT 20
- The entities will be processed in the order in which they were added to the registry when iterate over a view? HOT 1
- `entt::internal::group_handler::swap_elements` affects storages that are not owned by the group HOT 7
- Call the destructor twice HOT 1
- error: "use of overloaded operator '!=' is ambiguous" for `dense_map`-iterator? HOT 18
- 3.13.0 installs include/BUILD.bazel HOT 10
- entt::registry has no member empty and each wtf HOT 8
- `entt::registry::clear()` does not "clear enough" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entt.