Repository navigation
Document choosing a spatial hash cell size - #2935
Merged
Merged
Conversation
The performance tips said the cell size affects collision checks but not how to choose it, and the SpriteList docs only gave the default. Add a "Choosing a Cell Size" section with measurements: about the size of the sprites in the list. Much bigger cells make checks look at many sprites (4 px sprites: 200 checks take 33 ms with 128 px cells, 2.1 ms with 8 px ones); much smaller ones make adding and moving sprites slower. Link it from the SpriteList and enable_spatial_hashing() docstrings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Documents how to choose
spatial_hash_cell_size. The performance tips said the cell size affects collision checks, but not how to choose it, and theSpriteListdocs only gave the default. While measuring the Pixel Demolition demo (#2931), I found that the default of 128 is about 16× too slow for tiny sprites.Changes
Performance tips: a new "Choosing a Cell Size" section under Spatial Hashing. The advice is to use a cell size about the size of the sprites in the list, because:
It includes a table of measurements and a code example, and links to the Pixel Demolition example.
SpriteList(spatial_hash_cell_size=...)andenable_spatial_hashing()docstrings: the same advice in one line, plus a link to the section.Measurements
Measured on my desktop, with a grid of 2,400 sprites:
No code changes. The docs build with
sphinx-build -W, the new section renders with its table, and both docstrings link to it. Ruff is clean.The changelog has an entry under Unreleased → Misc Changes.
🤖 Generated with Claude Code