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

Avoid Unnecessary Autoboxing & Allocations #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

amcrn
Copy link

@amcrn amcrn commented Nov 7, 2017

  • KeyUtil.getKeyBytes(String) was being called twice for every Key,
    causing unnecessary byte[] allocations.
  • flags is more often than not 0, therefore send 0 as a String vs.
    an int to avoid autoboxing the int to an Integer and requiring
    unnecessary String.valueOf(Integer) + Integer.toString()
    allocations.
  • exp is commonly 0 (for never expire), and therefore send 0 as a
    String vs. an int to avoid the same issue mentioned above for
    flags.

If flags is 0 and exp is 0, ~10% less garbage is allocated as a
result of this optimization.

* KeyUtil.getKeyBytes(String) was being called twice for every Key,
  causing unnecessary byte[] allocations.
* flags is more often than not 0, therefore send 0 as a String vs.
  an int to avoid autoboxing the int to an Integer and requiring
  unnecessary String.valueOf(Integer) + Integer.toString()
  allocations.
* exp is commonly 0 (for never expire), and therefore send 0 as a
  String vs. an int to avoid the same issue mentioned above for
  flags.

If flags is 0 and exp is 0, ~10% less garbage is allocated as a
result of this optimization.
@ingenthr ingenthr self-assigned this Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants