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

Memoize the result of the module lookup #725

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sriedel
Copy link
Contributor

@sriedel sriedel commented Jun 16, 2019

Memoizes the expensive module lookup of RDoc::Mixin#module.

Note: It may be that a memoization of the result is not feasable due to changes in the loaded datastructures between calls, which would render this change moot.

Motivation: Generating the ri documentation for a lot of gems is very very slow. Looking at the process after the inital parsing phase, a lot of time is spent in repeated lookups of the module of a mixin. While the method contains lots of early returns, no early return seems to be possible if the logic falls through to the final @name return of the method, and watching the behaviour of the code it seems the same lookup can happen dozens of times for the very same Mixin instance, each time completing the entire method without early return.

A prominent example would be generating documentation for the http-2.8.3. With the unchanged code, generating ri documentation takes over 30 minutes on my gen 6 i7. In fact, I cancelled the jobs after 30 minutes:

~/.rvm/gems/ruby-2.6.3/gems/httpclient-2.8.3 $ time rdoc --ri
Parsing sources...
100% [67/67]  test/test_webagent-cookie.rb

Generating RI format into /home/sr/.rdoc...
^C
Interrupted

real	31m29.441s
user	31m28.062s
sys	0m0.199s

With the proposed changes, building the ri documentation takes about 3 seconds:

~/.rvm/gems/ruby-2.6.3/gems/httpclient-2.8.3 $ time rdoc --ri
Parsing sources...
100% [67/67]  test/test_webagent-cookie.rb

Generating RI format into /home/sr/.rdoc...

  Files:        67

  Classes:      91 ( 54 undocumented)
  Modules:      17 ( 10 undocumented)
  Constants:    94 ( 84 undocumented)
  Attributes:  140 ( 87 undocumented)
  Methods:     726 (511 undocumented)

  Total:      1068 (746 undocumented)
   30.15% documented

  Elapsed: 2.8s


real	0m3.235s
user	0m2.994s
sys	0m0.209s

Copy link
Member

@aycabta aycabta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't reproduce the slow rdoc --ri for httpclient-2.8.3. I tried HEAD and v6.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants