Skip to content

Commit 0b39cca

Browse files
committed
Remove ancestors from a method chain of checking include module
I used Stackprof for this optimization of CRuby documents generation with a patch below. --- a/exe/rdoc +++ b/exe/rdoc @@ -16,8 +16,11 @@ end require 'rdoc/rdoc' begin - r = RDoc::RDoc.new - r.document ARGV + require 'stackprof' + StackProf.run(mode: :cpu, out: 'stackprof.dump') do + r = RDoc::RDoc.new + r.document ARGV + end rescue Errno::ENOSPC $stderr.puts 'Ran out of space creating documentation' $stderr.puts Before this commit, RDoc::TopLevel#text? uses processing time about 19.3%. ~/rdoc$ stackprof stackprof.dump --text --limit 5 ================================== Mode: cpu(1000) Samples: 54814 (0.47% miss rate) GC: 9022 (16.46%) ================================== TOTAL (pct) SAMPLES (pct) FRAME 10579 (19.3%) 10579 (19.3%) RDoc::TopLevel#text? 9022 (16.5%) 9022 (16.5%) (garbage collection) 21611 (39.4%) 2503 (4.6%) RDoc::Generator::Darkfish#generate_class 3151 (5.7%) 1482 (2.7%) Ripper::Lexer#lex 1271 (2.3%) 1271 (2.3%) Ripper::Lexer::State#initialize After this commit, processing time of RDoc::TopLevel#text? is reduced to 6.8%. ~/rdoc$ stackprof stackprof.dump --text --limit 5 ================================== Mode: cpu(1000) Samples: 42712 (0.47% miss rate) GC: 6066 (14.20%) ================================== TOTAL (pct) SAMPLES (pct) FRAME 6066 (14.2%) 6066 (14.2%) (garbage collection) 2892 (6.8%) 2892 (6.8%) RDoc::TopLevel#text? 14059 (32.9%) 2379 (5.6%) RDoc::Generator::Darkfish#generate_class 3015 (7.1%) 1389 (3.3%) Ripper::Lexer#lex 1265 (3.0%) 1265 (3.0%) Ripper::Lexer::State#initialize Therefore, this commit speeds up RDoc by 9.9%.
1 parent a27b086 commit 0b39cca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/rdoc/top_level.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def search_record
272272
# Is this TopLevel from a text file instead of a source code file?
273273

274274
def text?
275-
@parser and @parser.ancestors.include? RDoc::Parser::Text
275+
@parser and @parser.include? RDoc::Parser::Text
276276
end
277277

278278
def to_s # :nodoc:

0 commit comments

Comments
 (0)