-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Node#each_recursive
performance
#139
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
41e13e9
Improve `Node#each_recursive` performance
makenowjust 5d93a49
Update `each_recursive` test
makenowjust 3640dcc
Update test/test_document.rb
makenowjust 81f7227
Fix some code stylings
makenowjust f6efe5f
Move `test_each_recursive`
makenowjust File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
loop_count: 100 | ||
contexts: | ||
- gems: | ||
rexml: 3.2.6 | ||
require: false | ||
prelude: require 'rexml' | ||
- name: master | ||
prelude: | | ||
$LOAD_PATH.unshift(File.expand_path("lib")) | ||
require 'rexml' | ||
- name: 3.2.6(YJIT) | ||
gems: | ||
rexml: 3.2.6 | ||
require: false | ||
prelude: | | ||
require 'rexml' | ||
RubyVM::YJIT.enable | ||
- name: master(YJIT) | ||
prelude: | | ||
$LOAD_PATH.unshift(File.expand_path("lib")) | ||
require 'rexml' | ||
RubyVM::YJIT.enable | ||
|
||
prelude: | | ||
require 'rexml/document' | ||
|
||
xml_source = +"<root>" | ||
100.times do | ||
x_node_source = "" | ||
100.times do | ||
x_node_source = "<x>#{x_node_source}</x>" | ||
end | ||
xml_source << x_node_source | ||
end | ||
xml_source << "</root>" | ||
|
||
document = REXML::Document.new(xml_source) | ||
|
||
benchmark: | ||
each_recursive: document.each_recursive { |_| } |
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we improve
REXML::Elements#each(nil)
case instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a possible improvement. But, IMHO, it can be split into another pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need to change
REXML::Node#each_recursive
when we improveREXML::Elements#each(nil)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation is best so like that we don't need to change it when we improve something.
I don't really like implementations that are optimized when using specific arguments. From that point of view, I'm not very keen on optimizing
each(nil)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
elements.each(nil)
is improved, we can useelements.each { |x| yield x }
instead ofeach { |x| yield x if x.node_type == :element }
.However, I don't think it is a problem that there are some duplications of
each { |x| yield x if x.node_type == :element }
sometimes. Becauseelements.each(&)
has some overheads and the performance is more important here.Repeatedly, I talked about the performance. The maintainability and other matters are out of topic here because the speed of
each_recursive
is one of the crucial parts of the XML library.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a maintainer, I don't agree it.
But I can understand your opinion as a heavy
each_recursive
user.OK. Let's focus on only
each_recursive
in this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your understanding!