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

feat: Add support for async loading using either futures or tokio AsyncRead traits #69

Merged
merged 5 commits into from
Jan 20, 2025

Conversation

debroejm
Copy link
Contributor

Fixes #68

Implements AsyncRead trait support for specifically futures and tokio. Other frameworks can of course be added as needed.

Remove duplicated code between load_obj_buf() and load_obj_buf_async(),
by refactoring out the majority of logic to helper structs. Now, only
the async-specific logic is different in load_obj_buf_async(), which
should significantly help in preventing it from bitrotting.
In order to allow proper async loading of objs and materials, the reader
 needs to be async itself. Unfortunately there are no standard async
 read/write traits, so the best solution is to implement per-framework
 async functions for the known big frameworks, gated behind feature
 flags.

 This commit adds support for `futures` AsyncRead traits.
In order to allow proper async loading of objs and materials, the reader
 needs to be async itself. Unfortunately there are no standard async
 read/write traits, so the best solution is to implement per-framework
 async functions for the known big frameworks, gated behind feature
 flags.

 This commit adds support for `tokio` AsyncRead traits.
Add the missing `async` dependency to futures/tokio features, so they
also pull in the relevant async bits.

Also do a slight rename to fix a warning for building with only the
`futures` feature.
Copy link
Owner

@Twinklebear Twinklebear left a comment

Choose a reason for hiding this comment

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

Thanks @debroejm I think this looks good! We can just mark the old async API deprecated and then this is good to

The original load_obj_buf_async() function is not properly async, since
it doesn't use async readers. Deprecate this function and point to the
new ones.
@debroejm
Copy link
Contributor Author

Added the deprecation.

Hmm, there is theoretical performance improvement in the async path, where loading materials is delayed until after the entire OBJ buffer is read, and then all materials can be asynchronously loaded at the same time (instead of one at a time while reading the OBJ buffer), but this would only really matter for an OBJ with a quite large count of separate material buffers, and would require a significant change in logic to delay the material loading. Probably something that can be added in the future if deemed necessary.

@Twinklebear Twinklebear merged commit e12775c into Twinklebear:master Jan 20, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for async readers
2 participants