Improve Element#attribute
implementation as 6500x faster
#146
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.
Element#namespaces
is heavy method because this method needs to traverse all ancestors of the element.Element#attribute
callsnamespaces
redundantly, so it is much slower.This PR reduces
namespaces
calls inElement#attribute
. Also, this PR removes a redundantrespond_to?
becausenamespaces
must returnHash
in the current implementation.Below is the result of a benchmark for this on my laptop.
This result shows that
Element#attribute
is now 6500x faster than the old implementation ifnamespace
is not supplied.It seems strange that it is slower when YJIT is enabled, but we believe this is a separate issue.
Thank you.