-
Notifications
You must be signed in to change notification settings - Fork 743
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
Stash base dir paths in module constants #1416
Conversation
This comment has been minimized.
This comment has been minimized.
Do you have an opinion @jneen? The idea makes sense to me but the overall reduction seems pretty small. |
Memory profiling summary--- master https://travis-ci.org/rouge-ruby/rouge/jobs/646657531
+++ PR https://travis-ci.org/rouge-ruby/rouge/jobs/646846491
- Total allocated: 13.90 MB (140145 objects)
+ Total allocated: 13.86 MB (139773 objects)
- Total retained: 5.32 MB (37776 objects)
+ Total retained: 5.32 MB (37780 objects) |
a6857a6
to
68565e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. While the performance improvement is minor, I think the real benefit comes from having the loading path be more clearly expressed.
@ashmaroli I realise you split #1430 off from this one so that #1430 could more easily be merged. I'd still like to discuss that one but having looked at this, I think it's helpful in more clearly expressing intent. And, as you pointed out, it reduces memory usage! Thanks for submitting it :) |
…-ruby#1416) Rouge makes use of dynamic loading of files at various points throughout its codebase. In these instances, the method `Kernel#__dir__` is used. This commit instead uses module constants to more clearly express intent and, as a bonus, reduce the number of object allocations required.
__dir__
allocates a new string on each call. Using this method in string interpolation(
"#{__dir__}/...."
) or path based methods (File.join(__dir__, ....)
, etc) results in duplication of the newly generated string.This allocation can be reduced by stashing the value in frozen module / class constants.