-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Avoid reading the entire asset into memory during asset processing. #21925
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
base: main
Are you sure you want to change the base?
Changes from all commits
5cfcb48
85432e7
8248adb
7110da5
5dd402a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --- | ||
| title: Changes to the `Process` trait in `bevy_asset`. | ||
| pull_requests: [21925] | ||
| --- | ||
|
|
||
| `ProcessContext` no longer includes `asset_bytes`. This has been replaced by `asset_reader`. To | ||
| maintain current behavior in a `Process` implementation, you can read all the bytes into memory. | ||
| If previously, you did: | ||
|
|
||
| ```rust | ||
| // Inside `impl Process for Type` | ||
| let bytes = context.asset_bytes(); | ||
| // Use bytes here! | ||
| ``` | ||
|
|
||
| Then now, it should be: | ||
|
|
||
| ```rust | ||
| // Inside `impl Process for Type` | ||
| let reader = context.asset_reader(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a nice helper for this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intentionally don't want to. We should be encouraging users to engage with the "buffered" API of reading and writing, to reduce how much memory we're using. Today a lot of our loaders and sources just read everything into memory, and that can really limit how much data we can process. Besides, this is exactly how users should be doing it in loaders anyway, so this is no different. This migration is just weird because the previous behavior of having all the bytes is weird. |
||
| let mut bytes = vec![]; | ||
| reader | ||
| .read_to_end(&mut bytes) | ||
| .await | ||
| .map_err(|err| ProcessError::AssetReaderError { | ||
| path: context.path().clone_owned(), | ||
| err: err.into(), | ||
| })?; | ||
| // Use bytes here! | ||
| ``` | ||
Uh oh!
There was an error while loading. Please reload this page.