Skip to content

Add fold method to Batch and PreparedQueryIter - #456

Merged
Ralith merged 1 commit into
Ralith:masterfrom
newDINO:master
Aug 31, 2026
Merged

Add fold method to Batch and PreparedQueryIter#456
Ralith merged 1 commit into
Ralith:masterfrom
newDINO:master

Conversation

@newDINO

@newDINO newDINO commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Add their fold implementation and benchmarks.

For PreparedQueryIter, there is a −67% time decrease: from 25us to 8.1us.
For Batch, there is basically no improvement. But due to the uncertainty of compiler optimization, I think this may still be useful.

@newDINO

newDINO commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

I also think it is worth mentioning that for_each has better performance than for-loop in the documentation, especially when the there is no much computation per iteration, and it can achieve performance close to iterating over rust built-in slices.

bevy_ecs also has this kind of mentioning (https://docs.rs/bevy_ecs/latest/bevy_ecs/system/struct.Query.html#iteratorfor_each).

@Ralith

Ralith commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Thanks! If you're currently using prepared queries, I recommend trying without them now that query caching is automatic.

@Ralith
Ralith merged commit f924648 into Ralith:master Aug 31, 2026
5 checks passed
@newDINO

newDINO commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the recommendation. Currently I'm not using PreparedQuery due to its !Sync limitations and that it's not very ergonomic.

On my machine, the automatically cached query only takes tens of nanoseconds, which is highly efficient.

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.

2 participants