Memoize the result of the module lookup #725
Open
+7
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
With the proposed changes, building the ri documentation takes about 3 seconds: