Skip to content

Instantly share code, notes, and snippets.

View guizmaii's full-sized avatar
🏄‍♂️

Jules Ivanic guizmaii

🏄‍♂️
View GitHub Profile
@guizmaii
guizmaii / ExecutionContextMonitor.scala
Created June 2, 2017 11:11 — forked from atamborrino/ExecutionContextMonitor.scala
Monitor Scala's ExecutionContext / Akka Dispatcher lag (number of tasks in waiting queues)
import java.util.concurrent._
import akka.dispatch.{Dispatcher, ExecutorServiceDelegate}
import config.Config
import helpers.ScalaLogger
class ExecutionContextMonitor()(implicit metricsService: MetricsClient, config: Config) {
private val log = ScalaLogger.get(this.getClass)
private val scheduler = Executors.newSingleThreadScheduledExecutor()
@guizmaii
guizmaii / amifind.sh
Created August 10, 2017 11:23 — forked from vancluever/amifind.sh
Find the most recent Ubuntu AMI using aws-cli (or any other AMI for that matter)
#!/bin/sh
# Use AWS CLI to get the most recent version of an AMI that
# matches certain criteria. Has obvious uses. Made possible via
# --query, --output text, and the fact that RFC3339 datetime
# fields are easily sortable.
export AWS_DEFAULT_REGION=us-east-1
aws ec2 describe-images \
@guizmaii
guizmaii / amifind.sh
Created August 10, 2017 11:23 — forked from vancluever/amifind.sh
Find the most recent Ubuntu AMI using aws-cli (or any other AMI for that matter)
#!/bin/sh
# Use AWS CLI to get the most recent version of an AMI that
# matches certain criteria. Has obvious uses. Made possible via
# --query, --output text, and the fact that RFC3339 datetime
# fields are easily sortable.
export AWS_DEFAULT_REGION=us-east-1
aws ec2 describe-images \
@guizmaii
guizmaii / integer.rb
Created August 29, 2017 08:16 — forked from pithyless/integer.rb
Ruby Integer::MAX and Integer::MIN
class Integer
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 16
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
p Integer::MAX #=> 4611686018427387903
p Integer::MAX.class #=> Fixnum
p (Integer::MAX + 1).class #=> Bignum
@guizmaii
guizmaii / latency.txt
Created December 1, 2017 21:55 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD

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

@guizmaii
guizmaii / NonEmptySet.scala
Created March 24, 2018 16:48 — forked from channingwalton/NonEmptySet.scala
NonEmptySet Implementation
import cats.data.NonEmptyList
import cats.Eq
import scala.collection.GenTraversableOnce
sealed trait NonEmptySet[T] extends (T => Boolean) {
def head: T
def set: Set[T]
def +(t: T): NonEmptySet[T]
def ++(ts: NonEmptySet[T]): NonEmptySet[T]
@guizmaii
guizmaii / NonEmptySet.scala
Created March 24, 2018 16:48 — forked from channingwalton/NonEmptySet.scala
NonEmptySet Implementation
import cats.data.NonEmptyList
import cats.Eq
import scala.collection.GenTraversableOnce
sealed trait NonEmptySet[T] extends (T => Boolean) {
def head: T
def set: Set[T]
def +(t: T): NonEmptySet[T]
def ++(ts: NonEmptySet[T]): NonEmptySet[T]
@guizmaii
guizmaii / x.scala
Created May 28, 2018 16:24 — forked from kevinmeredith/x.scala
Run IO[List[Int]] in Parallel using Ammonite
@ import $ivy.`org.typelevel::cats-effect:0.10.1`
@ import cats._, cats.data._, cats.implicits._, cats.effect._
@ def lift(i: Int): IO[Int] = Timer[IO].sleep(1.second) >> IO {
println(Thread.currentThread.getName + "At time = " + java.time.Instant.now)
i
}
@guizmaii
guizmaii / x.scala
Last active May 28, 2018 16:28 — forked from kevinmeredith/x.scala
Run IO[List[Int]] in Parallel using Ammonite
@ import $ivy.`org.typelevel::cats-effect:0.10.1`
@ import cats._, cats.data._, cats.implicits._, cats.effect._, scala.concurrent.duration._, import scala.concurrent.ExecutionContext.Implicits.global
@ def lift(i: Int): IO[Int] = Timer[IO].sleep(1.second) >> IO {
println(Thread.currentThread.getName + "At time = " + java.time.Instant.now)
i
}