[PROF-10112] Also simplify actionview templates with three underscores #3774
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.
What does this PR do?
This PR is a small fix on top of #3759. In that PR, we added code to detect method names dynamically generated by Rails actionview templates, slicing the parts of the method name that have random ids.
E.g.
_app_views_layouts_explore_html_haml__2304485752546535910_211320
became_app_views_layouts_explore_html_haml
.When looking at one of our example applications, I realized that I was seeing methods that ended with both
__number_number
as well as___number_number
(three vs two underscores), e.g.:_app_views_articles_index_html_erb___2022809201779434309_12900
_app_views_articles_index_html_erb__3816154855874711207_12920
On closer inspection of the actionview template naming code in https://github.com/rails/rails/blob/4fa56814f18fd3da49c83931fa773caa727d8096/actionview/lib/action_view/template.rb#L389:
... I realized that when
@identifier.hash
was a negative number, it would be printed including the - sign, which would be replaced by thetr
into another_
. (It's somewhat weird that they didn't just go withhash.abs
but yeah... >_>).Thus, there was a 50-50 chance that methods end up with three underscores, which would make them not merge together in the flamegraph.
This PR fixes this.
Motivation:
Make sure that these dynamically-generated methods merge together properly in a flamegraph.
Additional Notes:
Here's the issue in practice -- notice the purple frame ends with both
_erb
and_erb_
:...and here's how it looked without the previous patch as well:
How to test the change?
This change includes test coverage.