Skip to content

feat(lifetime)!: debug info and wait_no_references #888

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TestingPlant
Copy link
Collaborator

wait_no_references allows the packet bump allocator to wait until there are no more references before clearing the bump allocator instead of aborting if there are any references. Debug information is also added.

Copy link

Benchmark Results for general

ray_intersection/aabb_size_0.1                     [  34.1 ns ...  34.1 ns ]      +0.05%
ray_intersection/aabb_size_1                       [  33.4 ns ...  33.5 ns ]      +0.13%
ray_intersection/aabb_size_10                      [  24.2 ns ...  24.3 ns ]      +0.17%
ray_intersection/ray_distance_1                    [  13.7 ns ...  13.8 ns ]      +0.47%
ray_intersection/ray_distance_5                    [  13.8 ns ...  13.8 ns ]      -0.24%
ray_intersection/ray_distance_20                   [  13.8 ns ...  13.8 ns ]      -0.09%
overlap/no_overlap                                 [  24.8 ns ...  24.8 ns ]      -0.03%
overlap/partial_overlap                            [  25.1 ns ...  25.0 ns ]      -0.42%
overlap/full_containment                           [  22.5 ns ...  22.5 ns ]      -0.15%
point_containment/inside                           [   4.9 ns ...   4.9 ns ]      -0.00%
point_containment/outside                          [   4.4 ns ...   4.4 ns ]      +0.08%
point_containment/boundary                         [   5.0 ns ...   5.0 ns ]      +0.13%

Comparing to 4c402d0

wait_no_references allows the packet bump allocator to wait until there
are no more references before clearing the bump allocator instead of
aborting if there are any references. Debug information is also added.
@TestingPlant TestingPlant changed the title feat(lifetimne): add debug and wait_no_references feat(lifetime)!: debug info and wait_no_references Apr 27, 2025
Copy link

Benchmark Results for general

ray_intersection/aabb_size_0.1                     [  34.0 ns ...  34.0 ns ]      -0.08%
ray_intersection/aabb_size_1                       [  33.8 ns ...  33.8 ns ]      -0.11%
ray_intersection/aabb_size_10                      [  25.9 ns ...  25.9 ns ]      +0.10%
ray_intersection/ray_distance_1                    [  13.6 ns ...  13.5 ns ]      -0.44%
ray_intersection/ray_distance_5                    [  13.6 ns ...  13.6 ns ]      +0.22%
ray_intersection/ray_distance_20                   [  13.6 ns ...  13.6 ns ]      -0.12%
overlap/no_overlap                                 [  24.8 ns ...  24.8 ns ]      -0.16%
overlap/partial_overlap                            [  24.8 ns ...  24.9 ns ]      +0.08%
overlap/full_containment                           [  22.5 ns ...  22.6 ns ]      +0.24%
point_containment/inside                           [   5.5 ns ...   5.4 ns ]      -0.42%
point_containment/outside                          [   4.9 ns ...   4.9 ns ]      +0.63%
point_containment/boundary                         [   5.0 ns ...   5.0 ns ]      -0.36%

Comparing to 4c402d0

Copy link

codecov bot commented Apr 27, 2025

Codecov Report

Attention: Patch coverage is 26.73267% with 74 lines in your changes missing coverage. Please review.

Project coverage is 20.87%. Comparing base (4c402d0) to head (3a0bedc).

Files with missing lines Patch % Lines
crates/hyperion-utils/src/lifetime.rs 26.00% 73 Missing and 1 partial ⚠️
@@            Coverage Diff             @@
##             main     #888      +/-   ##
==========================================
+ Coverage   20.85%   20.87%   +0.02%     
==========================================
  Files         161      161              
  Lines       16867    16931      +64     
  Branches      468      473       +5     
==========================================
+ Hits         3518     3535      +17     
- Misses      13285    13332      +47     
  Partials       64       64              
Files with missing lines Coverage Δ
crates/hyperion/src/net/mod.rs 6.91% <100.00%> (ø)
crates/hyperion-utils/src/lifetime.rs 18.28% <26.00%> (+4.77%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andrewgazelka
Copy link
Member

can you go a little more into this?

in which scenarios would all the references not be 0 by the end of the gametick? I could see this causing issues if people accidentally hold onto references of say one event and then many bumps (massive memory) is never cleared

@TestingPlant
Copy link
Collaborator Author

TestingPlant commented Apr 27, 2025

in which scenarios would all the references not be 0 by the end of the gametick?

See #861 as an example of where this would occur. When events such as ChatMessage are processed with a multi_threaded system, the event processing threads may still be running and holding references while the clear_bump system runs and calls assert_no_references.

I could see this causing issues if people accidentally hold onto references of say one event and then many bumps (massive memory) is never cleared

This doesn't create multiple bump allocators. It waits until all references are cleared before clearing the bump allocator. If a reference is leaked, then wait_no_references will emit warnings every 5 seconds including debug information about which reference was leaked.

@andrewgazelka
Copy link
Member

in which scenarios would all the references not be 0 by the end of the gametick?

See #861 as an example of where this would occur. When events such as ChatMessage are processed with a multi_threaded system, the event processing threads may still be running and holding references while the clear_bump system runs and calls assert_no_references.

I could see this causing issues if people accidentally hold onto references of say one event and then many bumps (massive memory) is never cleared

This doesn't create multiple bump allocators. It waits until all references are cleared before clearing the bump allocator. If a reference is leaked, then wait_no_references will emit warnings every 5 seconds including debug information about which reference was leaked.

ideally there should be a sync point before assert_no_references though where it "reads" all event related things. I think we should prio fixing sync points over this.

@TestingPlant
Copy link
Collaborator Author

TestingPlant commented Apr 27, 2025

ideally there should be a sync point before assert_no_references though where it "reads" all event related things

wait_no_references is a sync point; the thread is parked until all references are dropped, meaning that all events with references have also finished processing. Once the last reference is dropped, the thread calling wait_no_references is unparked.

@andrewgazelka
Copy link
Member

ideally there should be a sync point before assert_no_references though where it "reads" all event related things

wait_no_references is a sync point; the thread is parked until all references are dropped, meaning that all events with references have also finished processing. Once the last reference is dropped, the thread calling wait_no_references is unparked.

what I am saying though is why not use flecs for this natively instead of having our own custom logic? flecs has sync points natively.

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.

2 participants