perf: Use a faster check for empty schemas #10444
Merged
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.
Experimentally, this can reduce time taken in calls to load a schema by 1-3 seconds, which for a Pulumi YAML program execution or call to
pulumi convert
(on the order of 5-10s) is a significant performance improvement.The benchmark showed that prior to this change, the benchmark took 1.1 to 2.5 seconds on a relatively recent Intel laptop processor:
Before:
(That's 1.7 seconds/operation, sample size of 1.)
After:
It's now on the order of a couple instructions, apparently too short for Go benchmarking to analyze (it is definitely not that much shorter than a nanosecond) as for most non-empty schemas we will return "false" within reading the first few bytes of a file.
Addenda: Out of curiosity I changed the regexp to include a
^
at the beginning, and that vastly improved performance. Still, the new approach is clear that we're willing to try to parse almost any document, just not the defaults that some providers have used.Again with the very tiny time per operation, a clock cycle on this computer is on the order of 0.25ns.