Skip to content

Instantly share code, notes, and snippets.

@bohford
Created December 1, 2011 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bohford/1414879 to your computer and use it in GitHub Desktop.
Save bohford/1414879 to your computer and use it in GitHub Desktop.
Stupid JRuby tricks
# JRuby 1.6.5 + Java 6
# 01 - Small Array Instantiation
# A new, empty array preallocates memory for 16 elements
# An array that starts non-empty and is subsequently cleared will only have memory allocated for one element
# Ergo, if you know your array will stay small, define with [nil].clear
empty_array = [] # 152 bytes
cleared_array = [nil].clear # 32 bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment