Skip to content

Instantly share code, notes, and snippets.

# From 981ns to 82ns: A UUIDv7 Optimization Story
I recently read an article on how the random nature of standard UUIDs can kill database performance due to index fragmentation. In the comments, someone mentioned UUIDv7 was designed to solve that very problem by being time-ordered and sortable.
Intrigued, I did a Google search for "kotlin uuidv7" and found an open-source implementation. I was currently using the standard `UUID.randomUUID()` (v4) combined with the `fast-uuid` library for fast string conversion. I swapped in the new UUIDv7 library, ran my benchmarks, and was immediately disappointed. It was slower.
But the library was open-source. And that’s where our story begins. What followed was a deep dive into the guts of UUID generation, peeling back layers of abstraction and overhead to chase every last nanosecond. This is the journey of how we made a UUIDv7 generator **~12x faster** than the native `java.util.UUID` on Android.
### The Baseline: Where We Started
class ResetChoreographerRule : TestRule {
override fun apply(
base: Statement?,
description: Description?
): Statement =
object : Statement() {
override fun evaluate() {
try {
val uiDispatcher: AndroidUiDispatcher = ReflectionHelpers.getField(AndroidUiDispatcher.Main, "element")
ReflectionHelpers.setField(uiDispatcher, "choreographer", Choreographer.getInstance())
@johngray1965
johngray1965 / build_pdfium.sh
Last active November 25, 2025 07:55
Script for build pdfium for Android
#! /bin/bash
# current the latest stable android branch (from Jan 2020)
githash=daabea6ba6c09f72e956e826b132f1d1b77acb9b
# if want to run this from somewhere other then /data adjust below
basedir=/data
# exit when any command fails
set -e