Skip to content

Instantly share code, notes, and snippets.

Quick Tips for Fast Code on the JVM

I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.

This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea

@tonymorris
tonymorris / cstx-packing-list.md
Last active March 6, 2018 21:55
CSTX Packing List

moved to CTX Packing List

moved consequent to github does not understand information security or privacy

@etorreborre
etorreborre / nothing.scala
Last active October 15, 2015 09:09
Nothing Scala gotcha
\/-(1).fold(
sys.exit(0),
t => { System.err.println(t); sys.exit(1) })
// this doesn't do the right thing, why?
// because it should be
\/-(1).fold(
_ => sys.exit(0),
t => { System.err.println(t); sys.exit(1) })
CREATE TABLE IF NOT EXISTS `continents` (
`code` CHAR(2) NOT NULL COMMENT 'Continent code',
`name` VARCHAR(255),
PRIMARY KEY (`code`)
) ENGINE=InnoDB;
INSERT INTO `continents` VALUES
('AF', 'Africa'),
('AS', 'Asia'),
('EU', 'Europe'),
import scalaz.std.anyVal._
import scalaz.std.tuple._
import scalaz.std.option._
import scalaz.StateT
import scalaz.State
import scalaz.Trampoline
import scalaz.syntax.traverse._
import scalaz.std.list._
import scalaz.Free
@kfox
kfox / forget.sh
Created February 8, 2013 15:45
An easy way to remove old SSH host keys from your ~/.ssh/known_hosts file. Useful if you often re-image systems.
# forget.sh: remove matching lines from ~/.ssh/known_hosts
# usage: forget <hostname|IP|substring> [...]
function forget {
known_hosts=~/.ssh/known_hosts
for host in $*
do
host=$(echo "${host}" | sed -e 's/^ssh:\/\///' -e 's/^.*@//')
line=$(awk '{ print $1 }' ${known_hosts} | grep -n "${host}" | sed 's/:.*$//g' | xargs)
while [ -n "${line}" ]
@coldnebo
coldnebo / Default (OSX).sublime-keymap -- User
Created February 3, 2012 16:21
Sublime Text 2 fix for OSX home/end keys
{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} }
@oxbowlakes
oxbowlakes / 3nightclubs.scala
Created May 13, 2011 15:14
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._