bevy/crates/bevy_reflect/src
Zachary Harrold 44620dd6ae
Split GenericTypeCell::get_or_insert into smaller pieces (#14865)
# Objective

Based on the discussion in #14864, I wanted to experiment with the core
`GenericTypeCell` type, whose `get_or_insert` method accounted for 2% of
the final binary size of the `3d_scene` example. The reason for this
large percentage is likely because the type is fundamental to the rest
of Bevy while having 3 generic parameters (the type stored `T`, the type
to retrieve `G`, and the function used to insert a new value `F`).

- Acts on #14864 

## Solution

- Split `get_or_insert` into smaller functions with minimised
parameterisation. These new functions are private as to preserve the
public facing API, but could be exposed if desired.

## Testing

- Ran CI locally.
- Used `cargo bloat --release --example 3d_scene -n 100000
--message-format json > out.json` and @cart's [bloat
analyzer](https://gist.github.com/cart/722756ba3da0e983d207633e0a48a8ab)
to measure a 428KiB reduction in binary size when compiling on Windows
10.
- ~I have _not_ benchmarked to determine if this improves/hurts
performance.~ See
[below](https://github.com/bevyengine/bevy/pull/14865#issuecomment-2306083606).

## Notes

In my opinion this seems like a good test-case for the concept of
debloating generics within the Bevy codebase. I believe the performance
impact here is negligible in either direction (at runtime and compile
time), but the binary reduction is measurable and quite significant for
a relatively minor change in code.

---------

Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
2024-08-26 18:20:01 +00:00
..
enums bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
func bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
impls Implement Reflect for std::ops::Bound (#14861) 2024-08-22 23:01:38 +00:00
path Apply unused_qualifications lint (#14828) 2024-08-21 12:29:33 +00:00
serde bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
array.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
attributes.rs Fix intra-doc links and make CI test them (#14076) 2024-07-11 13:08:31 +00:00
fields.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
from_reflect.rs reflect: implement the unique reflect rfc (#7207) 2024-08-12 17:01:41 +00:00
lib.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
list.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
map.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
reflect.rs bevy_reflect: Reflect remote types (#6042) 2024-08-12 19:12:53 +00:00
remote.rs bevy_reflect: Reflect remote types (#6042) 2024-08-12 19:12:53 +00:00
set.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
std_traits.rs fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
struct_trait.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
tuple.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
tuple_struct.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
type_info.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
type_path.rs Add on_unimplemented Diagnostics to Most Public Traits (#13347) (#13662) 2024-06-04 00:31:34 +00:00
type_registry.rs reflect: implement the unique reflect rfc (#7207) 2024-08-12 17:01:41 +00:00
utility.rs Split GenericTypeCell::get_or_insert into smaller pieces (#14865) 2024-08-26 18:20:01 +00:00