Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Remove usage of String in the asset manager #88

Closed
bjadamson opened this issue Sep 6, 2016 · 9 comments
Closed

Remove usage of String in the asset manager #88

bjadamson opened this issue Sep 6, 2016 · 9 comments
Labels
diff: easy Achievable by a single junior developer with a bit of guidance. pri: normal An issue that is causing a noticeable impact, but can be worked around type: improvement An improvement or change to an existing feature.
Projects
Milestone

Comments

@bjadamson
Copy link

Looking up resources by a string is convenient but slow thanks to dynamic allocation. I believe this is why OpenGL uses integer handles, even if it they are less convenient to work with.

These string should be replaced with type-safe integer wrappers, or some other design to improve the performance of the asset manager.
https://github.com/amethyst/amethyst/blob/develop/src/context/src/asset_manager.rs#L41-L42

Consideration must be given to the current convenience though, especially if it is removed.

Maybe offering both versions make sense? What does everyone think?

@OvermindDL1
Copy link

Shouldn't most asset strings have the 'key' only allocated once per app? If not then a flyweight string container could do that. That way you get a unique id comparison via taking the pointer of the string or the appropriate method in rust.

@bjadamson
Copy link
Author

bjadamson commented Sep 6, 2016

Shouldn't most asset strings have the 'key' only allocated once per app?

I agree this is probably true, but it's forcing the user to use a string when they otherwise would not. That's really what I'm trying to point out.

If not then a flyweight string container could do that. That way you get a unique id comparison via taking the pointer of the string or the appropriate method in rust.

This makes sense in the current implementation to me.

@bjadamson
Copy link
Author

bjadamson commented Sep 7, 2016

Here's a pull request showing what I'm thinking.

#90

Any thoughts? I'd like to audit everything for this change. I'm happy to add some implementation of string based asset-management that's built ontop of this, if that's desired. My real goal is to allow myself a path for not using strings here.

@leroycep
Copy link

leroycep commented Sep 7, 2016

Could we make it a generic so that the user can decide?

Another thought I had is making a build script that takes a resource file and bakes the strings into integers, similar to how android does it. The build script could generate a bunch of environment variables like AMETHYST_RESOURCE_ID_sphere_mesh=123. After the environment is generated, the user can just include using:

let sphere_resource = env!("AMETHYST_RESOURCE_ID_sphere_mesh");

Or even a custom macro so we can omit the prefix:

let sphere_resource = resource!("sphere_mesh");

Anyway, those are my thoughts. Don't know if we want to mess with build scripts.

@bjadamson
Copy link
Author

I like this, I think I can put a builder in front of this and make it general.

@leroycep
Copy link

leroycep commented Sep 7, 2016

Another thought: If we're going to deal with build scripts, we could just generate a "resources.rs" that contains all the resource constants. It would mean that all the env!() macros wouldn't need a u32::from_str().unwrap() surrounding them.

@Emilgardis
Copy link
Contributor

Emilgardis commented Sep 7, 2016

One way to have both i64's and String is to with #90 have each function take id: T where T: Into<*Id>
The one problem I can see are collisions. One way to fix this is to feature-flag i64 to only have one enabled, but I'm playing around trying to find a good solution.

@bjadamson
Copy link
Author

bjadamson commented Sep 7, 2016

Another thought, maybe it makes sense to always support static str& but String explicitly separately?

@ebkalderon ebkalderon added type: improvement An improvement or change to an existing feature. note: help wanted diff: easy Achievable by a single junior developer with a bit of guidance. pri: normal An issue that is causing a noticeable impact, but can be worked around and removed status: in-progress labels Sep 7, 2016
@ebkalderon ebkalderon added this to the 1.0 milestone Sep 14, 2016
@ebkalderon ebkalderon added this to In Progress in Engine Feb 3, 2017
@ebkalderon ebkalderon moved this from In Progress to Blocked in Engine Feb 3, 2017
@ebkalderon
Copy link
Member

The asset manager has changed significantly since the creation of this issue and uses &str as opposed to fat strings. I think I'll close this issue as it is no longer relevant.

@ebkalderon ebkalderon moved this from Blocked to Done in Engine Feb 3, 2017
@ebkalderon ebkalderon moved this from Done to Shipped in Engine Feb 7, 2017
@ebkalderon ebkalderon moved this from Shipped to Done in Engine Feb 7, 2017
@ebkalderon ebkalderon moved this from Done to Shipped in Engine Feb 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
diff: easy Achievable by a single junior developer with a bit of guidance. pri: normal An issue that is causing a noticeable impact, but can be worked around type: improvement An improvement or change to an existing feature.
Projects
No open projects
Engine
  
Shipped
Development

No branches or pull requests

5 participants