ruby / rdoc

RDoc produces HTML and online documentation for Ruby projects.
https://ruby.github.io/rdoc/
Other
833 stars 437 forks source link

Bad performance during mixin resolution #1126

Open Earlopain opened 2 months ago

Earlopain commented 2 months ago

Rails recently moved some includes from being dynamic to explicit in https://github.com/rails/rails/pull/52185 which means rdoc was now able to document a bit more. This had the side-effect of rdoc taking about 8 hours on that single file alone. Temporary solution was to wrap these in startdoc/stopdoc like https://github.com/rails/rails/pull/52185

I tried to investigate a bit and found this comment that mentions O(n!) https://github.com/ruby/rdoc/blob/4b846606904cc2db3999e5482c69a27f7d96947c/lib/rdoc/mixin.rb#L68-L73. That would certainly explain the horrible performance and looks like about what I found out myself.

I also have a potential fix which at least resolves this and tests pass. Check it out at #1127.

Repro:

# test.rb
require "rdoc/rdoc"

pp RDoc::RDoc::GENERATORS
options = RDoc::Options.new
options.template = "rdoc"
options.generator = RDoc::Generator::RI
options.files = ["code.rb"]
options.dry_run = true

rdoc = RDoc::RDoc.new
rdoc.document options
class Foo
  include A
  include B
  include C
  include D
  include E
  include F
  include G
  include H
  include I
  include J
  include K
  include L
  include M
  include N
  include O
  include P
  include Q
  include R
  include S
  include T
  include U
  include V
  include W
  include X
  include Y
  include Z
  include AA
  include AB
  include AC
  include AD
  include AE
  include AF
  include AG
  include AH
  include AI
  include AJ
  include AK
  include AL
  include AM
  include AN
  include AO
  include AP
end