Skip to content

Add block-to-mesh mapping system for improved mesh tracking#384

Open
tracygardner wants to merge 1 commit intomainfrom
claude/optimize-mesh-lookups-APAMf
Open

Add block-to-mesh mapping system for improved mesh tracking#384
tracygardner wants to merge 1 commit intomainfrom
claude/optimize-mesh-lookups-APAMf

Conversation

@tracygardner
Copy link
Contributor

Summary

This PR introduces a comprehensive block-to-mesh mapping system to replace inefficient object lookups. The changes add three new Map-based data structures to track relationships between blocks, block IDs, and their associated meshes, along with a registration function to maintain these mappings.

Key Changes

  • New mapping structures: Added blockToKeyMap, blockIdToKeyMap, and blockKeyMeshesMap to provide O(1) lookup performance instead of O(n) array searches
  • Registration function: Implemented registerMeshForBlockKey() to centralize mesh registration across all mesh creation points
  • Generator updates: Updated all 20+ block generator definitions to populate the new mapping structures whenever meshes are created
  • Lookup optimization: Refactored getBlockKeyFromBlock(), getBlockKeyFromBlockID(), getMeshFromBlockKey(), and getMeshesFromBlockKey() to use Map lookups instead of array filtering
  • Disposal handling: Enhanced getMeshFromBlockKey() and getMeshesFromBlockKey() to filter out disposed meshes
  • Cleanup: Updated deleteMeshFromBlock() to properly clean up all three mapping structures
  • Initialization: Reset all three maps in both init() and init2() generator initialization functions

Implementation Details

  • The blockKeyMeshesMap uses a Set to handle multiple meshes per block key
  • All mesh creation APIs (shapes.js, csg.js, camera.js, mesh.js) now call registerMeshForBlockKey() to maintain consistency
  • The mapping system is initialized fresh on each generator initialization to prevent stale references
  • Disposed mesh filtering ensures only active meshes are returned from lookup functions

https://claude.ai/code/session_011y6sJ1hJUwznDNwHzcphiQ

Replace linear scans in getBlockKeyFromBlock, getBlockKeyFromBlockID,
getMeshFromBlockKey, and getMeshesFromBlockKey with direct Map lookups.

- Add blockToKeyMap, blockIdToKeyMap, and blockKeyMeshesMap to generators.js
- Maintain all 5 Maps together at every assignment site (17 locations)
- Clear all Maps at both generator init/init2 reset sites
- Register meshes via registerMeshForBlockKey in api/shapes.js, api/mesh.js,
  api/csg.js, and api/camera.js at each metadata.blockKey assignment
- Rewrite the 4 lookup functions in blockmesh.js to use Map.get() / Set iteration
- Clean up reverse Maps in deleteMeshFromBlock on disposal

https://claude.ai/code/session_011y6sJ1hJUwznDNwHzcphiQ
@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 56551f82-6d67-463c-92f6-09be163b6f8a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can customize the tone of the review comments and chat replies.

Configure the tone_instructions setting to customize the tone of the review comments and chat replies. For example, you can set the tone to Act like a strict teacher, Act like a pirate and more.

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