Repository navigation
Leaner generated validation code (~1.5x on object-heavy schemas), no behavior change - #233
Closed
John-Cusack wants to merge 1 commit into
Closed
John-Cusack wants to merge 1 commit into
John-Cusack wants to merge 1 commit into
Conversation
required without set ops, no dead _keys set when nothing consumes it, tuple membership for all-string enums. Same exception types, messages, definitions and rules; full suite green, checksums and error samples identical stock-vs-patched on the frozen workload.
Author
|
Closing this. The title and changelog say no behavior change, which isn't true: |
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.
Leaner generated validation code (~1.5x on object-heavy schemas), no behavior change
What
Three pure-Python codegen-shape changes to the generated
validatefunctions (
fastjsonschema/draft04.pyonly — same shapes apply todraft06/draft07if you want them; kept this PR todraft04tostay reviewable):
generate_required): emit[key for key in [...] if key not in data]instead ofset([...]) - data.keys(). Same exception type, message(
str(sorted(missing))),definition, andrule; the setconstruction moves off the valid path.
_keysset (generate_properties/generate_pattern_properties/generate_additional_properties):skip building, probing (
in), and pruning (.remove) the{variable}_keysset when no consumer exists at that object level(
additionalPropertiesabsent/True/{}and nopropertyNames: false); directif "key" in {variable}guardsinstead.
generate_enum): for all-string enumsemit
if x not in ('a', 'b', ...)instead of the per-optionisinstance-and-==or-chain. Same message,definition,rule.Correctness guard included: trivially-checkless schemas
(
properties: {},patternProperties: {}, vacuousadditionalProperties: true/{}) previously relied on theunconditional
_keysline to keep the generatedifblock non-empty;with it gone, those shapes emitted an empty
ifbody(
IndentationErrorat compile). The trivial returns are now hoistedabove the block so no empty
ifis ever generated (verified: thoseschemas compile and validate correctly on this branch).
Measured
Ryzen 9 5950X, CPython 3.12.3, frozen 3000-doc nested-order batch
(compile-once excluded by construction), each arm a fresh subprocess,
in-process timing after warmup, min-of-7 per arm with arms interleaved
round-robin (shared box), peak RSS via
/procVmHWM:Ratios stable across two full interleaved runs (rep 1.48x both runs;
valid 1.62–1.73x; x1 1.88–1.92x). Peak RSS flat across arms (~23 MB
rep/valid, ~17.6 MB x1 both sides). Outcome checksums (sha256 over
valid/invalid outcomes) and error samples (message, name, rule,
definition on the first 40 docs) agree stock-vs-patched on all
tracks.
Reproduce (at 738da70 vs this branch, venv per
Makefilepip install -e .[devel]+ the JSON-Schema-Test-Suite submodule):python bench_fjs.py rep # + valid, x1; repeat per arm, take min(Bench scripts with the frozen corpus available on request — say the
word and I'll attach them.)
Test / lint proof
pytest -W default --benchmark-skip(theirmake testgate):4539 passed, 12 skipped, 435 xfailed, 950 xpassed — zero
failures (includes the JSON-Schema-Test-Suite submodule cases).
pylint fastjsonschema: 9.90/10, byte-identical score and warningset to unmodified master (no new warnings from this change).
CHANGELOG.txtentry added under=== UNRELEASED, matchingcontributor practice.