Report polymorphism for sprintf
nodes.
#3536
Closed
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.
While looking at the performance of a large Rails application, I saw that we were creating new
CallTarget
on each call toString#%
. The generic specialization compiles thesprintf
expression from scratch on each call, resulting in the creation of a new call target.The
sprintf
code can be invoked in a few different ways, but the one that stood out to me wasString#%
. Rails will create a request ID for each request to make tracking logs and such easier. The ActiveSupport code for creating the UUID uses a static format string, but thesprintf
nodes are already megamorphic by the time this code is called. I saw it go megamorphic by loading the URI library.I suspect format strings are mostly static and splitting would make most call sites monomorphic. This simple change demonstrably splits with the following example:
For call sites with > 3 format strings we could add a global cache, like we do for regular expressions. That could cut down on the creation of unique call targets, but that's out of scope for this PR and I don't have any evidence of it being a real world problem at the moment.