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

use handleid in renderer instead of a weak handle #4016

Closed
wants to merge 4 commits into from

Conversation

mockersf
Copy link
Member

  • The renderer only need a weak handle, so it can work with the HandleId
  • Tiny perf improvement
  • This was already done for the sprites

next question would be to replace the type uuid by a smaller unique id: uuid is backed by a u128, but a u64 would be largely enough to have a unique id for asset types, and make the HandleId enum the same size for both variants

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Feb 22, 2022
@mockersf mockersf added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Feb 22, 2022
@alice-i-cecile
Copy link
Member

next question would be to replace the type uuid by a smaller unique id: uuid is backed by a u128, but a u64 would be largely enough to have a unique id for asset types, and make the HandleId enum the same size for both variants

Yes, I think this is reasonable. We can only have u64::MAX entities anyways.

@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change C-Performance A change motivated by improving speed, memory usage or compile times labels Feb 22, 2022
@mockersf
Copy link
Member Author

Moved the uuid to a u64 internally, but still kept the same api where you need to provide a Uuid on the derive because it's prettier... and I didn't want to change the derive macro without other opinions.

This wins around 3 fps on many_sprites and many_cubes...

@alice-i-cecile
Copy link
Member

This wins around 3 fps on many_sprites and many_cubes...

Wow, that's way more than I expected.

@mockersf mockersf force-pushed the handleid-in-renderer branch from 8455c37 to c6f5189 Compare February 24, 2022 01:26
@superdump
Copy link
Contributor

Moved the uuid to a u64 internally, but still kept the same api where you need to provide a Uuid on the derive because it's prettier... and I didn't want to change the derive macro without other opinions.

This wins around 3 fps on many_sprites and many_cubes...

3fps out of how many? :) Cool!

@mockersf
Copy link
Member Author

many_cubes many_sprites
before 80~84 67~68
after 84~86 68~70

Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some places in the code, functions and such are still called 'uuid' which feels incorrect as uuid is something specific and this is not a uuid anymore.

Also, I haven't thought about the consequences and I'm imagining that @cart has. :)

@mockersf
Copy link
Member Author

mockersf commented Mar 2, 2022

In some places in the code, functions and such are still called 'uuid' which feels incorrect as uuid is something specific and this is not a uuid anymore.

Also, I haven't thought about the consequences and I'm imagining that @cart has. :)

Yup, before taking the step to yank all references and use of uuid, I was waiting for someone who may have ideas about unexpected consequences...

and then, for the derive, having a uuid does look nicer than having a random u64...

@bjorn3
Copy link
Contributor

bjorn3 commented Mar 2, 2022

I think the asset type should keep using an uuid. A u64 is not enough to be almost certain that the type id's chosen by different plugins are globally unique across all plugins. If this is not the case, trying to use plugins with conflicting type id's will cause surprising and incorrect results that may be hard to debug.

@mockersf
Copy link
Member Author

mockersf commented Mar 2, 2022

trying to use plugins with conflicting type id's will cause surprising and incorrect results that may be hard to debug.

Nop, it panics. there is a check when adding a new asset type that panics if its ID is already registered, and the message should be explicit enough

@bjorn3
Copy link
Contributor

bjorn3 commented Mar 3, 2022

That will still prevent the plugins from being used at the same time.

@mockersf
Copy link
Member Author

mockersf commented Mar 13, 2022

Neither uuid or u64 are a perfect solution to prevent collisions... and people will copy paste existing values from sample code
Until we have an plugin catalogue capable of warning of collisions, I'm not sure that will be a solved issue

@cart
Copy link
Member

cart commented May 25, 2022

Some assorted thoughts:

  • I like the idea of trying to reduce the runtime cost of handles.
  • I would like to retain type safety on the renderer side. Weak handles should be "cheap enough" to use in this context. If they aren't (clearly there is currently a cost here), thats something worth resolving.
  • Uuid should always only mean "actual uuid". TypeUuid should continue being a real Uuid. It is the standard way to avoid collisions in a distributed context.
  • Its worth considering "exchanging" a UUID for a "runtime atomically incrementing id" for assets, which could be much smaller.
  • In the very near future I'll be picking up the "asset preprocessing" area. Some or all of this code might change as a result.
  • bevy_reflect owning something like UniqueAssetId feels wrong.
  • I'd like to explore treating assets as entities. In that world, we'd be using entity ids (potentially inside a typed handle) in place of HandleIds.

@alice-i-cecile
Copy link
Member

In that world, we'd be using entity ids (potentially inside a typed handle)

For context / cross-linking, this is the kinded entities idea from #1634.

@mockersf mockersf closed this Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Code-Quality A section of code that is hard to understand or change 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.

5 participants