Skip to content

Instantly share code, notes, and snippets.

I might take a week to respond. Or a month.

Jakub Kozłowski kubukoz

I might take a week to respond. Or a month.
View GitHub Profile
jboner / latency.txt
Last active May 23, 2022
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers (~2012)
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
paulp / global.sbt
Last active Oct 16, 2018
continuous compilation of the sbt build
View global.sbt
// These lines go in ~/.sbt/0.13/global.sbt
watchSources ++= (
(baseDirectory.value * "*.sbt").get
++ (baseDirectory.value / "project" * "*.scala").get
++ (baseDirectory.value / "project" * "*.sbt").get
addCommandAlias("rtu", "; reload ; test:update")
addCommandAlias("rtc", "; reload ; test:compile")
addCommandAlias("ru", "; reload ; update")

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.


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

Daenyth / ByteStream.scala
Created Apr 8, 2019
ByteStream for fs2 - type-tagged byte encoding for Stream[F, Byte]
View ByteStream.scala
package teikametrics
import java.nio.charset.{Charset, StandardCharsets}
import akka.util.ByteString
import fs2.{Chunk, Pipe, RaiseThrowable, Stream}
import teikametrics.ByteEncoding._
/** Streamed bytes claiming to be encoded under `BE`
* @param chunkSize A chunk size to use for streaming operations, in order to use a consistent value and minimize array copying

Okay, I've got a need to build Firefox from source, and I'd like to do that on a remote machine, and then copy build result back to my laptop. With Nix, using bastion host. I'll note details of my successful adventure.

Setup & Sources of knowledge

Here's the list of resources I've used actively:

Here's my setup:


Since macOS Catalina, the root drive is read-only. The solution is to create a separate APFS volume and a “synthetic” /nix directory which points to it:

# Check if /nix exists, if not:
echo 'nix' | sudo tee -a /etc/synthetic.conf
# this will create a "synthetic" empty directory /nix

# REBOOT so macOS sees the synthetic directory

# After rebooting, create an APFS volume for Nix


Fibers are an abstraction over sequential computation, similar to threads but at a higher level. There are two ways to think about this model: by example, and abstractly from first principles. We'll start with the example.

(credit here is very much due to Fabio Labella, who's incredible Scala World talk describes these ideas far better than I can)

Callback Sequentialization

Consider the following three functions