-
-
Notifications
You must be signed in to change notification settings - Fork 906
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
Use the same empty string literal #1970
Use the same empty string literal #1970
Conversation
Code Climate has analyzed commit 2e15d37 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 0.0% (80% is the threshold). This pull request will bring the total coverage in the repository to 46.2%. View more on Code Climate. |
b6d8983
to
2e15d37
Compare
@ashmaroli Thanks for submitting this! The failing test is related to coverage diffs, and that's related to the config issue documented in #1965. This will be in v1.11.0! |
@flavorjones Glad to know that this will be included in |
Strange.. this didn't have an affect at all..
nokogiri/lib/nokogiri/xml/node.rb Line 767 in e6b3229
nokogiri/lib/nokogiri/xml/node.rb Line 780 in 8ce75d1
|
@ashmaroli are you saying you didn't test it both ways before submitting the PR? or are you saying the change didn't make it into 1.11.0? i'm a little confused by your response. |
OK - Please explain to me how you're profiling so I can either revert or fix. |
I've opened a new issue, #1986, to investigate. @ashmaroli I'd love your help there. |
What problem is this PR intended to solve?
Avoidable extra memory allocation
While profiling a project to optimize memory usage, the following came to my notice:
which is:
nokogiri/lib/nokogiri/xml/node.rb
Line 767 in e6b3229
The explanation is that
'a string of any length' * 0 == ""
.String#*
generates a new string even if string literals are frozen via the pragma.Therefore, if the above line was executed (with
indent_times == 0
) a 100 times, there would be an allocation of 100 empty strings (irrespective ofindent_text
) .This PR replaces this deterministic allocation with a single frozen string literal.
(Hope the native method doesn't mutate it).
Have you included adequate test coverage?
No change in behavior.
Does this change affect the C or the Java implementations?
N/A