Repository navigation
Format the name for $ref calls with only the loop variables it uses - #239
Merged
Merged
Conversation
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.
A
$refinitems,additionalItems,patternPropertiesoradditionalPropertiescalls the referenced function one time for each item. To make the name for each call, the generated code uses.format(**locals()). This copies all local variables of the function on each call. Now the generated code gives only the loop variables of the path, for example.format(data_x=data_x). The output does not change.items: {$ref}, 1000 stringsadditionalProperties: {$ref}, 500 keys$reftree, 511 nodesThe table shows CPython 3.15. CPython 3.14 gives the same results. On CPython 3.10, these rows are 22% to 32% faster.
I measured no slowdown on the
performance.pyschema (valid and invalid values) and on objects and arrays without$ref. I also measured no slowdown oncompile()andcompile_to_code()of the draft-04 and draft-07 metaschemas.compile_to_code()of a test schema that has only 150$refin loops is 1.5% to 2.3% slower. I used 20 to 30 interleaved rounds and a Mann-Whitney test (Apple M5, CPython 3.10, 3.14 and 3.15). I did not measure other architectures.Tests:
pytest -W default --benchmark-skippasses: 4758 passed, with the same skipped, xfailed and xpassed counts asmaster.pylint fastjsonschemagives the same warnings asmaster(9.90/10).value,name,path,definitionandrule.CHANGELOG.txthas an entry under UNRELEASED.