This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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 |