8000 Query caching via PreparedQuery is a big speedup for empty queries — should hecs always cache queries? · Issue #399 · Ralith/hecs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Query caching via PreparedQuery is a big speedup for empty queries — should hecs always cache queries? #399
Closed
@LPGhatguy

Description

@LPGhatguy

I found that preparing queries that match no entities were eating a lot of time in our game. For reference, we run on the order of 200 queries per frame. Here is the timing of some of our fastest systems. There is a big cliff between the systems that don't query the world versus those that do:

Image

I tried refactoring one of these systems to use PreparedQuery instead and saw a speedup of around 15x when that query matches no entities. Here is the before and after code of the system: https://gist.github.com/LPGhatguy/dcec605c3b6d058332f5ae527af6efde

...so naturally I thought I'd try caching all of my queries automatically! I implemented a quick bodge around World::query to do that caching: https://gist.github.com/LPGhatguy/2c6180540e45c6fd411456af560f9d64

The speedup on the fastest systems was a lot and I saved around 1.5ms per frame! Here's the updated chart of the fastest systems for comparison:

Image

I imagine that a hecs-native solution could be faster, use less janky unsafe, and then would apply to everyone who uses the library. I've found that this change is a very large speedup and maybe it would be for other games too!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0