perf: Optimize isRecursive check in DynamicModelCompiler #1458
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.
This fixes #1258
DynamicSchemaIndex.load
times before and after this change for some models tested on Intel® Core™ i7-10875H × 16 64GB RAM. Testing script was mostly based on the one from the issue.A model that consists of "aws-quicksight-spec" and "aws-sagemaker-spec".
A confidential model:
The new implementation has been tested manually with mentioned models against the old one and they both return the same results; however, it should be noted that the first model contains only a single recursive shape, while the confidential model contains only a few more.
The implementation is fully based on @Baccata's idea. My plan was to check that approach and then move to implementing mentioned Tarjan algorithm, but this implementation turned out to be quite fast. I don't mind implementing Tarjan but I propose to stop here, as at the moment the current solution is fast enough. Implementing Tarjan would probably yield better results but I think that the increase in complexity outweighs potential gains in speed. This decision can always be revisited in the future if needed.
PR Checklist (not all items are relevant to all PRs)