Repository navigation
Simplify instantiate_record_from_json with a cached per-class lookup table - #130
Closed
tungleduyxyz wants to merge 1 commit into
Closed
tungleduyxyz wants to merge 1 commit into
tungleduyxyz wants to merge 1 commit into
Conversation
…table Resolve each JSON key once per class into [setter, cardinality, type] (copy-on-write cache, cleared when attributes are declared) instead of walking ancestors, underscoring twice and rescuing NoMethodError for every key of every record. Unknown keys are cached and skipped without raising. Split the method into smaller pieces. Add specs for nested has_one/has_many, inherited metadata, unknown fields and cache invalidation, plus benchmark/from_json.rb (benchmark-ips). Refs killbill#126 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
Author
|
Superseded by #131 (same commit, opened from a branch in this repository instead of a fork). |
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.
Addresses #126 (partially; see "Not covered" below).
What
Resource.instantiate_record_from_jsonnow resolves each JSON key once per class into[setter, cardinality, type]and caches it, instead of per key/record doing anancestorswalk, twoUtils.underscorecalls, string interpolation andrescue nilfor unknown fields.has_one,has_many,attributeandcreate_alias.NoMethodError.instantiate_record_from_json,assign_json_attribute,build_manyand lookup helpers.has_one/has_manyand leniency: a setter that raises is still swallowed (rescue StandardError, free unless raised).Tests
New
spec/killbill_client/instantiate_record_from_json_spec.rb(14 examples): nested has_one/has_many, inherited metadata, no leak to parent, unknown fields ignored without exceptions, shape mismatches, nulls, cache invalidation, threads, and a realAccountTimeline. All but the no-exceptions example also pass on the old code. Full unit suite: 68 examples, 0 failures on CRuby 2.6.10 and JRuby 9.4.9.Benchmark
New
benchmark/from_json.rb(benchmark-ips, allocation and exception counts,Utils.underscore). UsePAYLOAD_DIRfor real captures; otherwise it generates synthetic payloads.Synthetic payloads, iterations/s:
CRuby allocations for the timeline: ~2.0M -> ~171k objects per parse.
Not covered (still open on #126)
rescue nilhit rate (synthetic payloads inject unknown fields, so the old-code exception counts are an artifact).Utils.underscoreis untouched; #125 stacks on top of this.