Skip to content
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

Remove or shrink bevy_utils #11478

Open
5 of 16 tasks
doonv opened this issue Jan 22, 2024 · 31 comments
Open
5 of 16 tasks

Remove or shrink bevy_utils #11478

doonv opened this issue Jan 22, 2024 · 31 comments
Labels
A-Utils Utility functions and types C-Code-Quality A section of code that is hard to understand or change

Comments

@doonv
Copy link
Contributor

doonv commented Jan 22, 2024

What problem does this solve or what need does it fill?

bevy_utils is a collection of unrelated utilities for Bevy. Utility modules/classes/libraries are generally frowned upon in the programming community since they are most likely a sign of poor organization.

What solution would you like?

Move bevy_utils's contents into existing bevy crates or into separate crates.

Long list of what to do with each item in bevy_utils

@doonv doonv added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Jan 22, 2024
@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change A-Utils Utility functions and types and removed C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Jan 22, 2024
@alice-i-cecile
Copy link
Member

Yes please: I want this crate eliminated!

@alice-i-cecile
Copy link
Member

I think we may want to spin up new crates in the Bevy org for some of the stand-alone utilities.

@cart, would that make sense to you? Things like the default function crate would be good to split out, and will change slowly enough that I don't have concerns about moving it out of the monorepo.

That said, I know you're reluctant about increasing crate number, just because it's a popular misguided punching bag for "dependency bloat".

@doonv
Copy link
Contributor Author

doonv commented Jan 22, 2024

I'm curious whats the compile-time performance penalty of switching between compiling different crates vs. the compile-time performance penalty of compiling unused parts of a crate.

@hymm
Copy link
Contributor

hymm commented Jan 22, 2024

label is used in bevy_ecs to define ScheduleLabel trait and SystemSet trait. So maybe should be there.

get_short_name is used in bevy_asset in a Debug impl, bevy_ecs for some ambiguity reporting, and bevy_heirarchy for a warning. So I don't think it makes sense in bevy_reflect which is an optional dependency for those crates. Not sure where it should go though.

@alice-i-cecile
Copy link
Member

get_short_name feels like a general purpose Rust utility, or maybe something that belongs in bevy_reflect for working with types and paths.

github-merge-queue bot pushed a commit that referenced this issue Feb 3, 2024
Use `TypeIdMap<T>` instead of `HashMap<TypeId, T>`

- ~~`TypeIdMap` was in `bevy_ecs`. I've kept it there because of
#11478~~
- ~~I haven't swapped `bevy_reflect` over because it doesn't depend on
`bevy_ecs`, but I'd also be happy with moving `TypeIdMap` to
`bevy_utils` and then adding a dependency to that~~
- ~~this is a slight change in the public API of
`DrawFunctionsInternal`, does this need to go in the changelog?~~

## Changelog
- moved `TypeIdMap` to `bevy_utils`
- changed `DrawFunctionsInternal::indices` to `TypeIdMap`

## Migration Guide

- `TypeIdMap` now lives in `bevy_utils`
- `DrawFunctionsInternal::indices` now uses a `TypeIdMap`.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
tjamaan pushed a commit to tjamaan/bevy that referenced this issue Feb 6, 2024
Use `TypeIdMap<T>` instead of `HashMap<TypeId, T>`

- ~~`TypeIdMap` was in `bevy_ecs`. I've kept it there because of
bevyengine#11478~~
- ~~I haven't swapped `bevy_reflect` over because it doesn't depend on
`bevy_ecs`, but I'd also be happy with moving `TypeIdMap` to
`bevy_utils` and then adding a dependency to that~~
- ~~this is a slight change in the public API of
`DrawFunctionsInternal`, does this need to go in the changelog?~~

## Changelog
- moved `TypeIdMap` to `bevy_utils`
- changed `DrawFunctionsInternal::indices` to `TypeIdMap`

## Migration Guide

- `TypeIdMap` now lives in `bevy_utils`
- `DrawFunctionsInternal::indices` now uses a `TypeIdMap`.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
github-merge-queue bot pushed a commit that referenced this issue Feb 12, 2024
# Objective

Reduce the size of `bevy_utils`
(#11478)

## Solution

Move `EntityHash` related types into `bevy_ecs`. This also allows us
access to `Entity`, which means we no longer need `EntityHashMap`'s
first generic argument.

---

## Changelog

- Moved `bevy::utils::{EntityHash, EntityHasher, EntityHashMap,
EntityHashSet}` into `bevy::ecs::entity::hash` .
- Removed `EntityHashMap`'s first generic argument. It is now hardcoded
to always be `Entity`.

## Migration Guide

- Uses of `bevy::utils::{EntityHash, EntityHasher, EntityHashMap,
EntityHashSet}` now have to be imported from `bevy::ecs::entity::hash`.
- Uses of `EntityHashMap` no longer have to specify the first generic
parameter. It is now hardcoded to always be `Entity`.
Subserial pushed a commit to Subserial/bevy_winit_hook that referenced this issue Feb 20, 2024
# Objective

Reduce the size of `bevy_utils`
(bevyengine/bevy#11478)

## Solution

Move `EntityHash` related types into `bevy_ecs`. This also allows us
access to `Entity`, which means we no longer need `EntityHashMap`'s
first generic argument.

---

## Changelog

- Moved `bevy::utils::{EntityHash, EntityHasher, EntityHashMap,
EntityHashSet}` into `bevy::ecs::entity::hash` .
- Removed `EntityHashMap`'s first generic argument. It is now hardcoded
to always be `Entity`.

## Migration Guide

- Uses of `bevy::utils::{EntityHash, EntityHasher, EntityHashMap,
EntityHashSet}` now have to be imported from `bevy::ecs::entity::hash`.
- Uses of `EntityHashMap` no longer have to specify the first generic
parameter. It is now hardcoded to always be `Entity`.
@Kanabenki
Copy link
Contributor

Kanabenki commented Feb 29, 2024

Regarding the tracing utiliities in bevy_utils, I checked whether that could be easily moved to bevy_log, but that creates a deps cycle since it already depends on bevy_app and bevy_ecs because of the LogPlugin. Would it make sense to have a bevy_tracing crate just for re-exporting tracing + the few tracing utilities?

github-merge-queue bot pushed a commit that referenced this issue Mar 7, 2024
# Objective
Make bevy_utils less of a compilation bottleneck. Tackle #11478.

## Solution
* Move all of the directly reexported dependencies and move them to
where they're actually used.
* Remove the UUID utilities that have gone unused since `TypePath` took
over for `TypeUuid`.
* There was also a extraneous bytemuck dependency on `bevy_core` that
has not been used for a long time (since `encase` became the primary way
to prepare GPU buffers).
* Remove the `all_tuples` macro reexport from bevy_ecs since it's
accessible from `bevy_utils`.

---

## Changelog
Removed: Many of the reexports from bevy_utils (petgraph, uuid, nonmax,
smallvec, and thiserror).
Removed: bevy_core's reexports of bytemuck.

## Migration Guide
bevy_utils' reexports of petgraph, uuid, nonmax, smallvec, and thiserror
have been removed.

bevy_core' reexports of bytemuck's types has been removed. 

Add them as dependencies in your own crate instead.
spectria-limina pushed a commit to spectria-limina/bevy that referenced this issue Mar 9, 2024
…e#12313)

# Objective
Make bevy_utils less of a compilation bottleneck. Tackle bevyengine#11478.

## Solution
* Move all of the directly reexported dependencies and move them to
where they're actually used.
* Remove the UUID utilities that have gone unused since `TypePath` took
over for `TypeUuid`.
* There was also a extraneous bytemuck dependency on `bevy_core` that
has not been used for a long time (since `encase` became the primary way
to prepare GPU buffers).
* Remove the `all_tuples` macro reexport from bevy_ecs since it's
accessible from `bevy_utils`.

---

## Changelog
Removed: Many of the reexports from bevy_utils (petgraph, uuid, nonmax,
smallvec, and thiserror).
Removed: bevy_core's reexports of bytemuck.

## Migration Guide
bevy_utils' reexports of petgraph, uuid, nonmax, smallvec, and thiserror
have been removed.

bevy_core' reexports of bytemuck's types has been removed. 

Add them as dependencies in your own crate instead.
github-merge-queue bot pushed a commit that referenced this issue Apr 8, 2024
# Objective

- Attempts to solve two items from
#11478.

## Solution

- Moved `intern` module from `bevy_utils` into `bevy_ecs` crate and
updated all relevant imports.
- Moved `label` module from `bevy_utils` into `bevy_ecs` crate and
updated all relevant imports.

---

## Migration Guide

- Replace `bevy_utils::define_label` imports with
`bevy_ecs::define_label` imports.
- Replace `bevy_utils::label::DynEq` imports with
`bevy_ecs::label::DynEq` imports.
- Replace `bevy_utils::label::DynHash` imports with
`bevy_ecs::label::DynHash` imports.
- Replace `bevy_utils::intern::Interned` imports with
`bevy_ecs::intern::Interned` imports.
- Replace `bevy_utils::intern::Internable` imports with
`bevy_ecs::intern::Internable` imports.
- Replace `bevy_utils::intern::Interner` imports with
`bevy_ecs::intern::Interner` imports.

---------

Co-authored-by: James Liu <contact@jamessliu.com>
@mnmaita
Copy link
Member

mnmaita commented Apr 26, 2024

label and intern modules were moved into bevy_ecs. You can tick those whenever you can. I might work on some other items on this list later. Thanks!

@mnmaita
Copy link
Member

mnmaita commented May 23, 2024

FloatOrd can be ticked as it was moved here.

Regarding stuff like CowArc and OnDrop, does it make sense to have these as crates within the bevy repo, or would it make more sense to have them as standalone repositories within the org?

@mintlu8
Copy link
Contributor

mintlu8 commented May 28, 2024

About HashMap, I suggest kill it completely and replace with rustc_hash::FxHashMap.

@tsal
Copy link

tsal commented Jun 15, 2024

did bevy::utils::thiserror get removed / moved as part of this effort in 0.14? I can't seem to find the module anymore, but that could be user error (no pun intended).

@BD103
Copy link
Member

BD103 commented Jun 15, 2024

did bevy::utils::thiserror get removed / moved as part of this effort in 0.14? I can't seem to find the module anymore, but that could be user error (no pun intended).

I believe it did. You can view the draft migration guide here.

@mnmaita
Copy link
Member

mnmaita commented Jun 15, 2024

BoxedFuture usage was reduced in #12550 but it still exists. Not sure if there will be a way to completely remove it though (check the convo on that PR for more context).

dekirisu pushed a commit to dekirisu/bevy_gltf_trait that referenced this issue Jul 7, 2024
# Objective

Reduce the size of `bevy_utils`
(bevyengine/bevy#11478)

## Solution

Move `EntityHash` related types into `bevy_ecs`. This also allows us
access to `Entity`, which means we no longer need `EntityHashMap`'s
first generic argument.

---

## Changelog

- Moved `bevy::utils::{EntityHash, EntityHasher, EntityHashMap,
EntityHashSet}` into `bevy::ecs::entity::hash` .
- Removed `EntityHashMap`'s first generic argument. It is now hardcoded
to always be `Entity`.

## Migration Guide

- Uses of `bevy::utils::{EntityHash, EntityHasher, EntityHashMap,
EntityHashSet}` now have to be imported from `bevy::ecs::entity::hash`.
- Uses of `EntityHashMap` no longer have to specify the first generic
parameter. It is now hardcoded to always be `Entity`.
@mnmaita
Copy link
Member

mnmaita commented Aug 14, 2024

Some thoughts on CowArc:

Do we really need this to exist in bevy_utils if it's not shared within bevy (it's only used in bevy_asset AFAICS)?
If it's exported because people are using it on their projects, do we really care to expose this considering they can vendor it or use the cow_arc crate (I understand this is a different implementation, but still)?
Should we be providing this at all, as a game engine?

All my answers to these questions are "No" right now, so I'll appreciate any counter arguments to them.

@cart
Copy link
Member

cart commented Aug 15, 2024

My arguments to include it:

  1. This CowArc has unique design constraints. Nothing else in the ecosystem fits the bill currently (to my knowledge).
  2. It exists in some of our public APIs.
  3. It fills a role that may have uses elsewhere in the engine.

From my perspective, that means we need to make this (publicly) available somewhere. In the interest of removing bevy_utils, I could be convinced to move it into bevy_asset. But that feels like it would be a temporary spot for it.

@alice-i-cecile
Copy link
Member

Could we ship a tiny crate for it? It seems genuinely useful to the ecosystem, and I think that dramatically more people will use it standalone.

@mnmaita
Copy link
Member

mnmaita commented Aug 16, 2024

I'm all in for a cart_arc crate honestly. 😆

I could work on any of these items FWIW, moving it temporarily to the asset crate and/or creating a new crate, but I'd need some support for the latter as I won't have the permissions to create a new repo within the org and publish a crate from it.

@alice-i-cecile
Copy link
Member

I'm on board with this, and have @cart's blessing. I'm on vacation this week, but please prompt me to get you set up on August 26, 2024.

@MarcGuiselin
Copy link

MarcGuiselin commented Sep 6, 2024

bevy_utils::{HashMap, HashSet} can be replaced with std::collections::{HashMap, HashSet} since hashbrown is now part of the std library. There's no reason to use hashbrown directly unless we care about no-std. (See https://github.com/rust-lang/hashbrown) The default hasher also uses aHash.

Should make for a very simple pr (I can open it), and it might reduce final bundle size since we arn't shipping an extra implementation, but are using the same implementation from std most devs already use.

About HashMap, I suggest kill it completely and replace with rustc_hash::FxHashMap.

For a future bevy with a nice modding system, I feel like the protection offered against HashDoS is a good thing... but I'm not entirely sure.

@mintlu8 Are there benchmarks for performance of rustc_hash compared to std::collections?

@hymm
Copy link
Contributor

hymm commented Sep 6, 2024

The default hasher for std library seems to be SipHash. https://doc.rust-lang.org/stable/std/collections/struct.HashMap.html

The default hashing algorithm is currently SipHash 1-3, though this is subject to change at any point in the future. While its performance is very competitive for medium sized keys, other hashing algorithms will outperform it for small keys such as integers as well as large keys such as long strings, though those algorithms will typically not protect against attacks such as HashDoS.

@MarcGuiselin
Copy link

Thanks @hymm, I stand corrected. So we don't want to use std::collections directly, but aliased in order to use aHash. That actually simplifies things.

@mintlu8
Copy link
Contributor

mintlu8 commented Sep 8, 2024

@mintlu8 Are there benchmarks for performance of rustc_hash compared to std::collections?

This is an old benchmark for rustc_hash 1.0. (fxHash)

https://medium.com/@tprodanov/benchmarking-non-cryptographic-hash-functions-in-rust-2e6091077d11

rustc_hash has since released 2.0 and uses a different algorithm. I will update this after I do a benchmark myself.

rustc_hash 2.0 uses a modified wyhash and it's a very good overall algorithm compared to the original fxHash, see relevent benchmarks from the same test suite in the article. Also unlike ahash, it's hardware independent, which is a plus.

https://pastebin.com/VTwYEN4L

@mintlu8
Copy link
Contributor

mintlu8 commented Sep 8, 2024

Side note: tracing re-export can probably just be removed since #[instrument] doesn't work if you don't have the actual tracing crate in your project.

@SkiFire13
Copy link
Contributor

bevy_utils::{HashMap, HashSet} can be replaced with std::collections::{HashMap, HashSet} since hashbrown is now part of the std library. There's no reason to use hashbrown directly unless we care about no-std. (See https://github.com/rust-lang/hashbrown) The default hasher also uses aHash.

Should make for a very simple pr (I can open it), and it might reduce final bundle size since we arn't shipping an extra implementation, but are using the same implementation from std most devs already use.

Note that hashbrown will still be in bevy's dependency tree due to indexmap (used by petgraph and naga) and gpu-descriptor (used by wgpu), so there likely won't be big benefits.

@BenjaminBrienen
Copy link
Contributor

BenjaminBrienen commented Sep 21, 2024

Addressing default:

The module exists to support an aesthetic preference. It can be removed easily (although it is a LOT of simple edits), but this won't happen unless a decision is first be made by leadership to stop preferring "..default()". Until then, we can't fully remove bevy_utils, but we can still minimize it.

github-merge-queue bot pushed a commit that referenced this issue Sep 21, 2024
# Objective

- Goal is to minimize bevy_utils #11478

## Solution

- Move the file short_name wholesale into bevy_reflect

## Testing

- Unit tests
- CI

## Migration Guide

- References to `bevy_utils::ShortName` should instead now be
`bevy_reflect::ShortName`.

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
@cart
Copy link
Member

cart commented Sep 24, 2024

Given how sensitive people are to "init ergonomics", I'm still very biased toward keeping and preferring ..default(). Imo "wanting to remove bevy_utils" is not a good enough reason to remove such a feature. We will always have things in that category, and we'll need somewhere to put them.

I don't like putting default() (or really anything) in bevy_internal, as that prevents things inside bevy_internal from depending on them.

bevy_utils exists to solve this exact kind of problem. We can't just pretend it doesn't exist. If there isn't a satisfying solution that is better than something bevy_utils-shaped, we should consider keeping it (in slimmed down form).

@teohhanhui
Copy link

teohhanhui commented Oct 3, 2024

..default() just feels like unnecessary deviation from idiomatic Rust. Does it really make any meaningful difference when we consider IDE auto-completion? And IMO considering that the typical Bevy app feels extremely verbose, ..default() seems like it'd be the least of our concerns...

But there's rust-lang/rfcs#1995 which might help in the future...

@BenjaminBrienen
Copy link
Contributor

..<_>::default() is also possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Utils Utility functions and types C-Code-Quality A section of code that is hard to understand or change
Projects
None yet
Development

No branches or pull requests