Skip to content
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

Bad performance during mixin resolution #1126

Open
Earlopain opened this issue Jun 27, 2024 · 0 comments
Open

Bad performance during mixin resolution #1126

Earlopain opened this issue Jun 27, 2024 · 0 comments

Comments

@Earlopain
Copy link
Contributor

Earlopain commented Jun 27, 2024

Rails recently moved some includes from being dynamic to explicit in rails/rails#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 rails/rails#52185

I tried to investigate a bit and found this comment that mentions O(n!)

rdoc/lib/rdoc/mixin.rb

Lines 68 to 73 in 4b84660

# This method has <code>O(n!)</code> behavior when the module calling
# include is referencing nonexistent modules. Avoid calling #module until
# after all the files are parsed. This behavior is due to ruby's constant
# lookup behavior.
#
# As of the beginning of October, 2011, no gem includes nonexistent modules.
. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant