-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Reduce allocations when parsing lockfile #6976
Reduce allocations when parsing lockfile #6976
Conversation
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.
Feel free to merge anyway if you don't think the @state
change is worth it.
@@ -149,11 +160,11 @@ def parse_dependency(line) | |||
return unless line =~ NAME_VERSION | |||
spaces = $1 | |||
return unless spaces.size == 2 | |||
name = $2 | |||
name = -$2 |
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.
Cute. I'm surprised this isn't used more often, enough that it's common practice. First I've seen it and had to look it up.
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.
I don't think I've seen this before, but I failed when I tried to look it up. What is it?
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.
Unary minus on String. It freezes the string returns a frozen version of the string. Unary + thaws.
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.
Huh, how about that. I guess I should have checked the API docs! I did finally find a writeup: https://metaredux.com/posts/2019/05/10/weird-ruby-positive-and-negative-strings.html
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.
@-
is an alias for #dedup
, which not only returns a frozen string, but will deduplicate it, leading to reduced retained memory usage
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.
FYI: The unary operator is -@
.
``` ==> memprof.after.txt <== Total allocated: 673.08 kB (7644 objects) Total retained: 107.35 kB (1018 objects) ==> memprof.before.txt <== Total allocated: 739.12 kB (9140 objects) Total retained: 138.61 kB (1695 objects) ``` Savings will scale by the number of lines in the lockfile
8c829df
to
f6abf44
Compare
…hen-parsing-lockfile Reduce allocations when parsing lockfile (cherry picked from commit 6a2fa57)
…hen-parsing-lockfile Reduce allocations when parsing lockfile (cherry picked from commit 6a2fa57)
…hen-parsing-lockfile Reduce allocations when parsing lockfile (cherry picked from commit 6a2fa57)
…hen-parsing-lockfile Reduce allocations when parsing lockfile (cherry picked from commit 6a2fa57)
Savings will scale by the number of lines in the lockfile
What was the end-user or developer problem that led to this PR?
What is your fix for the problem, implemented in this PR?
Make sure the following tasks are checked