rdoc icon indicating copy to clipboard operation
rdoc copied to clipboard

Bad performance during mixin resolution

Open Earlopain opened this issue 1 year ago • 0 comments

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

Earlopain avatar Jun 27 '24 07:06 Earlopain