Skip to content

[Merged by Bors] - Inline world get#2520

Closed
mockersf wants to merge 2 commits intobevyengine:mainfrom
mockersf:inline-world-get
Closed

[Merged by Bors] - Inline world get#2520
mockersf wants to merge 2 commits intobevyengine:mainfrom
mockersf:inline-world-get

Conversation

@mockersf
Copy link
Member

Objective

While looking at the code of World, I noticed two basic functions (get and get_mut) that are probably called a lot and with simple code that are not inline

Solution

  • Add benchmark to check impact
  • Add #[inline]
group                                            this pr                                main
-----                                            ----                                   ----
world_entity/50000_entities                      1.00   115.9±11.90µs        ? ?/sec    1.71   198.5±29.54µs        ? ?/sec
world_get/50000_entities_SparseSet               1.00   409.9±46.96µs        ? ?/sec    1.18   483.5±36.41µs        ? ?/sec
world_get/50000_entities_Table                   1.00   391.3±29.83µs        ? ?/sec    1.16   455.6±57.85µs        ? ?/sec
world_query_for_each/50000_entities_SparseSet    1.02   121.3±18.36µs        ? ?/sec    1.00   119.4±13.88µs        ? ?/sec
world_query_for_each/50000_entities_Table        1.03     13.8±0.96µs        ? ?/sec    1.00     13.3±0.54µs        ? ?/sec
world_query_get/50000_entities_SparseSet         1.00   666.9±54.36µs        ? ?/sec    1.03   687.1±57.77µs        ? ?/sec
world_query_get/50000_entities_Table             1.01   584.4±55.12µs        ? ?/sec    1.00   576.3±36.13µs        ? ?/sec
world_query_iter/50000_entities_SparseSet        1.01   169.7±19.50µs        ? ?/sec    1.00   168.6±32.56µs        ? ?/sec
world_query_iter/50000_entities_Table            1.00     26.2±1.38µs        ? ?/sec    1.91     50.0±4.40µs        ? ?/sec

I didn't add benchmarks for the mutable path but I don't see how it could hurt to make it inline too...

@github-actions github-actions bot added S-Needs-Triage This issue needs to be labelled S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work labels Jul 22, 2021
@alice-i-cecile
Copy link
Member

Looks like the comparable Query functions are in-lined already :)

@alice-i-cecile
Copy link
Member

Aha, the underlying get_unchecked_manual is not though:

pub unsafe fn get_unchecked_manual<'w>(

Is that worth doing? Should it be a seperate PR?

@mockersf
Copy link
Member Author

mockersf commented Jul 22, 2021

inlining get_unchecked_manual

group                                            inlined get_unchecked_manual           main
-----                                            ----                                   ----
world_entity/50000_entities                      1.00   113.4±10.84µs        ? ?/sec    1.75   198.5±29.54µs        ? ?/sec
world_get/50000_entities_SparseSet               1.00   404.5±43.74µs        ? ?/sec    1.20   483.5±36.41µs        ? ?/sec
world_get/50000_entities_Table                   1.00   407.7±54.59µs        ? ?/sec    1.12   455.6±57.85µs        ? ?/sec
world_query_for_each/50000_entities_SparseSet    1.00    107.0±9.75µs        ? ?/sec    1.12   119.4±13.88µs        ? ?/sec
world_query_for_each/50000_entities_Table        1.09     14.5±0.69µs        ? ?/sec    1.00     13.3±0.54µs        ? ?/sec
world_query_get/50000_entities_SparseSet         1.00  615.3±102.78µs        ? ?/sec    1.12   687.1±57.77µs        ? ?/sec
world_query_get/50000_entities_Table             1.00   407.1±44.08µs        ? ?/sec    1.42   576.3±36.13µs        ? ?/sec
world_query_iter/50000_entities_SparseSet        1.03   173.8±18.44µs        ? ?/sec    1.00   168.6±32.56µs        ? ?/sec
world_query_iter/50000_entities_Table            1.02     51.1±2.89µs        ? ?/sec    1.00     50.0±4.40µs        ? ?/sec

it does improve bench world_query_get/50000_entities_Table, but it loses the improvements on bench world_query_iter/50000_entities_Table (which I'm actually not sure why it improved in the first place, but they are nice though...)

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times and removed S-Needs-Triage This issue needs to be labelled S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work labels Jul 22, 2021
@cart cart added the S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work label Jul 23, 2021
@mockersf mockersf removed the S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work label Jul 24, 2021
@cart
Copy link
Member

cart commented Jul 27, 2021

Awesome! I love free performance. I think not including get_unchecked_manual is the right call, given the Table iterator regressions (which we try to keep in check).

Lets merge this as is and we can consider get_unchecked_manual later / maybe try tweaking other things so the stars align favorably.

@cart
Copy link
Member

cart commented Jul 27, 2021

bors r+

bors bot pushed a commit that referenced this pull request Jul 27, 2021
# Objective

While looking at the code of `World`, I noticed two basic functions (`get` and `get_mut`) that are probably called a lot and with simple code that are not `inline`

## Solution

- Add benchmark to check impact
- Add `#[inline]`


```
group                                            this pr                                main
-----                                            ----                                   ----
world_entity/50000_entities                      1.00   115.9±11.90µs        ? ?/sec    1.71   198.5±29.54µs        ? ?/sec
world_get/50000_entities_SparseSet               1.00   409.9±46.96µs        ? ?/sec    1.18   483.5±36.41µs        ? ?/sec
world_get/50000_entities_Table                   1.00   391.3±29.83µs        ? ?/sec    1.16   455.6±57.85µs        ? ?/sec
world_query_for_each/50000_entities_SparseSet    1.02   121.3±18.36µs        ? ?/sec    1.00   119.4±13.88µs        ? ?/sec
world_query_for_each/50000_entities_Table        1.03     13.8±0.96µs        ? ?/sec    1.00     13.3±0.54µs        ? ?/sec
world_query_get/50000_entities_SparseSet         1.00   666.9±54.36µs        ? ?/sec    1.03   687.1±57.77µs        ? ?/sec
world_query_get/50000_entities_Table             1.01   584.4±55.12µs        ? ?/sec    1.00   576.3±36.13µs        ? ?/sec
world_query_iter/50000_entities_SparseSet        1.01   169.7±19.50µs        ? ?/sec    1.00   168.6±32.56µs        ? ?/sec
world_query_iter/50000_entities_Table            1.00     26.2±1.38µs        ? ?/sec    1.91     50.0±4.40µs        ? ?/sec
```

I didn't add benchmarks for the mutable path but I don't see how it could hurt to make it inline too...
@bors bors bot changed the title Inline world get [Merged by Bors] - Inline world get Jul 27, 2021
@bors bors bot closed this Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants