Draft optimizations for upstream #19
Draft
+69
−58
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.
Summary of changes:
_extract
in (link PR), private_array
and_set
have been added to save in an additional memory allocation resulting from the extra*args
splat that would happen whenJbuilderTemplate#array!
andJbuilderTemplate#set!
's called back up tosuper
. With the new setup, the splat happens a single time.::Kernel.block_given?
showed up as hotspots on our profiling. These have been replaced with a simpleif block
check, which performs faster. Normally you wouldn't see a difference withblock_given?
, but sinceJbuilder
is aBasicObject
,::Kernel.block_given?
had to be used, and the extra module resolution apparently has some overhead.one?
showed up as hotspots in our profiling, which I believe it's an O(n) operation. Theargs.one?
guards have been removed, as they appeared to not actually be necessary. There were guards likeif args.one? && _partial_options?(options)
, and I presume theone?
was intended to short circuit the checks against theoptions
hash, but it's actually faster to just forgo theone?
call. If the intent was to check if only one argument was provided, this isn't actually doing that; it is actually checking if one truthy argument was provided.Some benchmarks against
JbuilderTemplate
comparingmain
(before) with this branch (after):set!
array!
via
method_missing