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

Tweaks to reduce memory use of short commands #5837

merged 6 commits into from Aug 19, 2019


Copy link

@headius headius commented Aug 17, 2019

This is a set of memory/alloc-reducing experiments that can be merged or cherry-picked as appropriate.

Copy link
Member Author

headius commented Aug 17, 2019

The failures appear to be due to 3dc4a9c, the first commit in this PR. For some reason the line number is off by one. @enebo Can you see why that would be?

This avoids creation of most Charset encoders, decoders, buffers,
and some intermediate byte[] and char[] instances created at boot
and by the parser.
The yacc logic did not use the out variable. The ripper logic was
simple to change to use a field. This eliminates allocation of
thousands of Encoding[1] during gem list.
Many arrays in the system are single elements, both in user code
and within our AST to represent things like argument lists. This
logic reduces the amount of wasted Node[] instances when a given
ListNode will only ever contain one element.

If a ListNode with a single element is grown, this logic
returns to a Node[] from then on.

This change, tested against `--dev -S gem list` reduce Node[] use
by the following numbers:


* Node[] allocated: 48002 (1536064 bytes)
* Node[] retained:  24900 (796800 bytes)


* Node[] allocated: 12390 (612576 bytes)
* Node[] retained:   6142 (303704 bytes)
The former pattern caused a StringBuilder and accompanying buffer
to be instantiated just to append a character and turn the buffer
into a String, at a cost of another additional char[].
String.valueOf allocates only the one-element char[] and the
String object itself.
Copy link
Member Author

headius commented Aug 17, 2019

I have re-pushed this with the failing source position patch moved to #5838.

@headius headius requested review from kares and enebo August 17, 2019 23:57
@headius headius added this to the JRuby milestone Aug 17, 2019
kares approved these changes Aug 18, 2019
Copy link

@kares kares left a comment

Choose a reason for hiding this comment

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

that one Thread.dumpStack() left-over but otherwise looks reasonable to me

This was inserted to detect if this Iterator implementation were ever used. None of my tests produced any output, and it apparently did not interfere with any tests in CI. Maybe it was needed before but it is apparently not used now.
Copy link
Member Author

headius commented Aug 19, 2019

I'm going to go ahead and merge this. @enebo any review issues you find I will patch later.

@headius headius merged commit 63f1716 into jruby:master Aug 19, 2019
@headius headius deleted the memory_tweaks branch August 19, 2019 17:56
@T45K T45K mentioned this pull request Aug 17, 2020
headius added a commit that referenced this pull request Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants