Optimize autocrafter with timestamp-based slot caching#40
Open
Distolfix wants to merge 1 commit intoSongoda-Plugins:masterfrom
Open
Optimize autocrafter with timestamp-based slot caching#40Distolfix wants to merge 1 commit intoSongoda-Plugins:masterfrom
Distolfix wants to merge 1 commit intoSongoda-Plugins:masterfrom
Conversation
Add timestamp-based caching to remember last output slot used, preventing inventory fragmentation and improving performance. Previous behavior iterated through all slots every craft to find where to place the output, often resulting in the same item type scattered across multiple slots (e.g., diamond blocks in slots 0, 1, and 4). Now caches the last used slot per hopper with a 60-second TTL. On subsequent crafts, it checks the cached slot first (O(1) instead of O(n)). If valid, uses it directly. If not, falls back to two-pass search: first looking for existing stacks of the same type, then for empty slots. This keeps inventory organized and reduces iteration overhead on every craft operation.
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
This PR optimizes the autocrafter module by adding timestamp-based caching to remember the last output slot used. This prevents inventory fragmentation and improves performance.
Problem
The autocrafter was iterating through all inventory slots on every single craft operation to find where to place the output item. This had two issues:
Solution
Implemented a slot caching mechanism with timestamp-based validation:
Technical Details
The caching logic:
Benefits
Testing
Tested with 10,000 diamonds being auto-crafted into diamond blocks: