Skip to content

Entity index merged - #523

Open
peterpothmann wants to merge 8 commits into
mlange-42:mainfrom
peterpothmann:entity-index-merged
Open

peterpothmann wants to merge 8 commits into
mlange-42:mainfrom
peterpothmann:entity-index-merged

Conversation

@peterpothmann

Copy link
Copy Markdown
Contributor

Stores the entity generation in the entity index and removes the entity list of the entity pool.

Map.Get, World.Alive etc. now read one array instead of two, which saves a cache miss per lookup in large worlds with shuffled entity IDs. Memory per entity drops from 16 to 12 bytes. No API change, EntityDump format unchanged.

With 100k entities for the benchmarks, "Map.Get shuffled" might still fit largely into the CPU caches (?). It might be worth extending it to 1M entities to show the effect of cache misses.

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (723f2ac) to head (ffbe5de).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #523   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           39        39           
  Lines         8409      8394   -15     
=========================================
- Hits          8409      8394   -15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🚀 2 benchmark improvements detected!

⚠️ 3 benchmark regressions detected!

Click to expand benchmark results

Time is per entity/N, allocations are totals. Allocations are only shown for current.

N       Time main             Time curr           Factor         Allocs         Bytes    
Add/Remove 1 of 2
10 97.91ns 100.15ns 1.03 0 0
1000 94.03ns 96.41ns 1.03 0 0
Add/Remove 1 of 2 non-trivial
10 107.00ns 111.08ns 1.05 0 0
1000 104.95ns 111.45ns 1.07 0 0
Add/Remove batch 1 of 11
10 64.64ns 68.08ns 1.06 0 0
1000 17.50ns 18.10ns 1.04 0 0
100000 51.92ns 48.57ns 1.00 0 0
Add/Remove batch 1 of 2
10 21.73ns 21.67ns 1.00 0 0
1000 6.34ns 6.17ns 0.98 0 0
100000 8.46ns 8.25ns 0.99 0 0
Add/Remove batch 1 of 2 non-trivial
10 39.10ns 40.89ns 1.05 0 0
100 22.89ns 22.05ns 0.96 0 0
1000 19.16ns 19.53ns 1.02 0 0
100000 21.07ns 21.10ns 1.00 0 0
Alive
10 0.54ns 0.71ns ⚠️ 1.30 0 0
1000 0.45ns 0.60ns ⚠️ 1.38 0 0
Map.Get shuffled
10 2.29ns 2.39ns 1.05 0 0
1000 2.30ns 2.26ns 0.98 0 0
100000 4.39ns 4.17ns 0.95 0 0
NewBatch 2 Comp
10 25.13ns 28.98ns ⚠️ 1.15 0 0
1000 11.16ns 10.73ns 0.96 0 0
NewBatch 5 Comp
10 25.11ns 27.55ns 1.10 0 0
1000 10.34ns 10.81ns 1.04 0 0
NewEntity 2 Comp
10 47.35ns 51.64ns 1.09 0 0
1000 26.94ns 27.90ns 1.03 0 0
NewEntity 5 Comp
10 47.95ns 51.77ns 1.08 0 0
1000 28.01ns 27.10ns 0.97 0 0
Pos/Vel mapper
10 5.77ns 5.94ns 1.03 0 0
1000 6.57ns 6.13ns 0.94 0 0
100000 15.04ns 15.00ns 0.99 0 0
Pos/Vel query entities
10 7.34ns 7.67ns 1.05 0 0
1000 2.06ns 2.11ns 1.02 0 0
100000 2.10ns 2.10ns 1.00 0 0
Pos/Vel query tables
10 6.74ns 6.72ns 1.00 0 0
1000 0.83ns 0.82ns 0.99 0 0
100000 1.05ns 1.09ns 1.04 0 0
Query create + close
1 31.64ns 32.44ns 1.03 0 0
Query(reg) create + close
1 32.37ns 32.89ns 1.02 0 0
RemoveEntity 2 Comp
10 36.44ns 37.37ns 1.03 0 0
1000 18.16ns 17.44ns 0.96 0 0
RemoveEntity 5 Comp
10 51.72ns 50.98ns 0.99 0 0
1000 29.77ns 28.65ns 0.96 0 0
RemoveEntityBatch 2 Comp
10 26.19ns 24.22ns 0.93 0 0
1000 4.75ns 3.77ns 🚀 0.80 0 0
RemoveEntityBatch 5 Comp
10 28.90ns 28.38ns 0.98 0 0
1000 5.37ns 4.49ns 🚀 0.84 0 0

Comment thread ecs/pool.go Resolved
Comment thread ecs/pool.go Resolved
@mlange-42

Copy link
Copy Markdown
Owner

@peterpothmann Any idea what changed that Map.Get has no regression anymore? Nice, though.

@peterpothmann

peterpothmann commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

@peterpothmann Any idea what changed that Map.Get has no regression anymore? Nice, though.

Also because of inlining: regression gone after "move Alive to storage" (56ebdbc). Before that, isAlive called entityPool.Alive, and that extra call made Map.Get expensive for the compiler to inline. Now the check sits directly in isAlive and Map.Get gets inlined again like on main.

It is quite close to the inline limit though (76 of 80), so small changes in Get could bring it back.

@mlange-42

Copy link
Copy Markdown
Owner

@peterpothmann Could you rebase (for the merged lock improvement) and resolve conflicts, please?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants