Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved RecipeMap Backing Storage #3007

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

TechLord22
Copy link

Ports 1.12 GTCEu's trie-based data structure, with some change. It should have much faster recipe search times than the current implementation.

Additionally, by its own nature, conflicts and duplicate recipes cannot be stored. All conflicts will have to not be added in the first place as a result. In this scenario, the first conflict will be the "winner" and the others will not be added.

A Spliterator is implemented to facilitate potentially performing these searches across multiple threads, but this has not been tested. It is also unlikely multithreading is ever needed here. Concurrent writes to the Trie are not supported, but concurrent reads are (provided that no writes happen concurrently while reading).

This PR also fixes a bug in ItemHolder's equals() implementation, which had an incorrect NBT equality check, and also improves its performance by reducing some extraneous object allocations and removal of unnecessary streams.

A brief overview of how this implementation works:
The data structure stores recipes by creating a pathway to them, with one input leading to the next input, and eventually leading to an ending recipe. It is made up of nodes and edges like a regular tree, but operations like tree-shaking and balancing are not performed. Edges in the trie are input ingredients, and nodes are either empty or a recipe. Empty nodes signify that there are more edges to traverse to higher depths. Because nodes cannot be both a recipe and more edges to traverse, conflicting recipes cannot be stored and prevents users from experiencing problems related to it. Recipe lookup walks the tree using the available inputs until a recipe is found.

In the current draft state of this PR, tests are not yet written, and the new data structure is not actively being used for lookup in machines yet. Logging is also disabled due to the massive amount of conflicts currently inside the GT5u repo alone. It should be re-enabled once these conflicts are dealt with.

@Dream-Master Dream-Master requested a review from a team September 1, 2024 08:46
@boubou19 boubou19 added the ongoing freeze - do not merge PR tagged with this do not meet the requirement to be merged during a freeze. label Sep 1, 2024
@boubou19 boubou19 added enhancement Improve an existing mechanic. Please explain the change with a before/after comparison. refactor For PRs rewritting a part of the code to have a nicer code overall. ongoing freeze - do not merge PR tagged with this do not meet the requirement to be merged during a freeze. and removed ongoing freeze - do not merge PR tagged with this do not meet the requirement to be merged during a freeze. labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve an existing mechanic. Please explain the change with a before/after comparison. ongoing freeze - do not merge PR tagged with this do not meet the requirement to be merged during a freeze. refactor For PRs rewritting a part of the code to have a nicer code overall.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants