-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Use u64 for change ticks #6327
Use u64 for change ticks #6327
Conversation
Allows detecting arbitrary old changes Simplifies a lot of code along the way
I would very much like #4972 merged before we attempt to merge this. This doubles the memory footprint of change detection, which will double the cache miss rate on all change detection filters and any query with mutative access. This potential regression should be weighed against the periodic cost of running |
Periodic cost of I can port optimization that I've made in |
Agreed with James on benchmarking. I'd also like the ability to opt-out of change detection as well, with ZSTs opted out by default. Marker components are very common and powerful, and I'd really like to avoid incurring performance costs to using them. While working on a production game, memory cost is one of my larger performance concerns (much higher than runtime CPU speed), and I think we can and should do better.
This would be very appreciated; I think this is a great direction, regardless of what we decide for the question in this PR. |
Unfortunately I can't see how to implement Opt-out change tracking would help with memory cost. |
We should make a couple assumptions here:
This method should just call self.ticks.component_ticks.is_changed, but passing in a manual last_changed_tick value :) IMO we should be making that first assumption (that last_changed_tick is early than current_change_tick) throughout. |
Imagine following situation.
What should happen? Current logic uses method In case of Possibly we can make only |
(Edit) I support this change, but I agree with @james7132. I don't think change ticks being Using #3956 goes over the reasoning behind the current value of Was also trying to be mindful of their footprint in case we have applications that want to send them in packets. |
That would require changing at least |
I think I asked the wrong question. Can you give a usage example where an app would be querying for an extremely old change? I'm looking for scenarios that would motivate doing this sooner, but atm it seems very niche. Normally, game sessions don't persist for days and systems don't run that infrequently. Edit:
Yeah, that seems like a fair compromise, |
Systems do not run this infrequently. The scenario I have in my head concerns |
Yes but, even with thousands of systems, over the course of days you wouldn't easily run into this. Detecting a change this old is borderline cronjob (i.e. weekly maintenance) level operations, for which this seems like a very poor approach to handling. |
Yes but, even with thousands of systems, over the course of days you wouldn't easily run into this. Detecting a change this old is borderline cronjob (i.e. weekly maintenance) level operations, for which this seems like a very poor approach to handling. EDIT: May have miscalculated. A 2,000 system game running at 60 TPS runs over the max change age every 7 hours. I still think this is a rather atypical use case, but I can see this happening regularly on a MMO or any other persistent game server. |
And there are lots of simpler games with persistent game server. And single player games can be running for days too. I agree that benchmarks should be used to see if this change hurts performance too much. Before that opt-out from changing tracking for components should be implemented. Together with |
If we merge #6547, this change will likely be perf neutral with the current status quo other than the 2x memory usage for change detection. I'll run microbenchmarks for this PR if/when that one is merged. |
I've prepared another PR with the same idea but that keeps using u32 for tick values of components. Not sure what would be better. To add |
Separate would be easier. The larger (and more controversial) it becomes, the harder it becomes to review and convince others that it's the right direction. |
Please leave this open. If #6547 gets merged, I think this one would likely be accepted. 2x memory use does seem like it would affect |
I've created #6651 anyway. Feel free to compare and pick one. |
Backlog cleanup: closing this and alternate approach #6651 due to inactivity, and no clear consensus. |
@richchurcher can you open an issue for this one? This is something @maniwani has wanted for years and it's a reasonable idea. Blocked on configurable change detection though. |
100%, and please tell me if you see any others flow past your notifications that need one too! Been trying to ask the various |
Tracked in #15683. |
Objective
Allows detecting arbitrary old changes
Simplifies a lot of code along the way
Would play nice with query that detects changes since arbitrary tick that I'll implement next.
Solution
Replace
u32
withu64
for tick values.Maintenance code to guard against overflow is simply removed.
Downside - requires
AtomicU64
.A workaround should be implemented for when
AtomicU64
is not available on target platform.Changelog
Changed
Type of values that represent ticks are changed from
u32
tou64
.World's
change_tick
isAtomicU64
now.Migration Guide
Some trait methods became obsolete and were removed.
Many users would need to change nothing as said traits are rarely used directly.