{"id":28637315,"url":"https://github.com/robsonkades/uuidv7","last_synced_at":"2026-01-30T22:39:58.237Z","repository":{"id":297536738,"uuid":"996437353","full_name":"robsonkades/uuidv7","owner":"robsonkades","description":"UUIDv7 is a small, high-performance Java library for generating UUID version 7 identifiers","archived":false,"fork":false,"pushed_at":"2025-09-17T10:00:07.000Z","size":19,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-17T12:11:03.739Z","etag":null,"topics":["high-performance","java","jvm","uuid","uuidv7"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robsonkades.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-05T00:32:15.000Z","updated_at":"2025-09-17T11:09:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"9be712ae-3048-4fa2-98dc-74527d9ee631","html_url":"https://github.com/robsonkades/uuidv7","commit_stats":null,"previous_names":["robsonkades/uuidv7"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robsonkades/uuidv7","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robsonkades%2Fuuidv7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robsonkades%2Fuuidv7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robsonkades%2Fuuidv7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robsonkades%2Fuuidv7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robsonkades","download_url":"https://codeload.github.com/robsonkades/uuidv7/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robsonkades%2Fuuidv7/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28921538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T22:32:35.345Z","status":"ssl_error","status_checked_at":"2026-01-30T22:32:31.927Z","response_time":66,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["high-performance","java","jvm","uuid","uuidv7"],"created_at":"2025-06-12T18:10:21.541Z","updated_at":"2026-01-30T22:39:58.232Z","avatar_url":"https://github.com/robsonkades.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UUIDv7\n\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.robsonkades/uuidv7)](https://search.maven.org/artifact/io.github.robsonkades/uuidv7)  \n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)  \n[![Build Status](https://github.com/robsonkades/uuid/actions/workflows/maven.yml/badge.svg)](https://github.com/robsonkades/uuid/actions)\n\n**UUIDv7** is a small, high-performance Java library for generating [UUID version 7](https://www.rfc-editor.org/rfc/rfc9562#name-uuid-version-7) identifiers, combining a 48-bit millisecond timestamp with 74 bits of high-quality entropy. Unlike the standard `java.util.UUID.randomUUID()`, this implementation:\n\n- Uses **ThreadLocalRandom** (non-blocking, fast PRNG) instead of `SecureRandom`.\n- Avoids intermediate `byte[16]` allocations and `ByteBuffer` overhead.\n- Produces about **50× the throughput** of a naïve implementation while still conforming to the RFC 9562 layout.\n- Minimizes per-UUID garbage (≈32 B per call vs. ≈176 B in a typical version).\n\nUUIDv7 is ideal for distributed systems, microservices, databases, and high-throughput applications that need time-sortable unique identifiers without sacrificing performance.\n\n---\n\n### Table of Contents\n\n1. [Features](#features)\n2. [Quick Start](#quick-start)\n3. [Performance Comparison](#performance-comparison)\n4. [License](#license)\n5. [Contributing](#contributing)\n\n---\n\n## Features\n\n- **Fully RFC-compliant** UUID v7 format (48 bits timestamp, 4 bits version, 2 bits variant, 74 bits random).\n- **Extremely low overhead**: only one `UUID` object allocation per call (≈32 bytes).\n- **High throughput**: bench tests show ~200 million UUID/s on modern hardware.\n- **Thread-safe**: uses `ThreadLocalRandom` internally.\n- **Zero external dependencies** beyond the JDK.\n- **Java 8+ compatible** (tested up through Java 17/21).\n\n---\n\n## Quick Start\n\n### Maven Dependency\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.github.robsonkades\u003c/groupId\u003e\n  \u003cartifactId\u003euuidv7\u003c/artifactId\u003e\n  \u003cversion\u003e1.0.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nAfter adding the dependency, run:\n\n```mvn clean install```\n\n# Performance Comparison \u0026 License\n\n## Performance Comparison\n\nBelow is a summary of benchmark results comparing the naïve UUIDv7 implementation (using `SecureRandom` + `ByteBuffer`) with this optimized implementation (using `ThreadLocalRandom` + bitwise assembly). All measurements were taken on a modern 8-core CPU (Intel/AMD), Java 17, Linux SSD, with JMH settings: 5 warmup iterations, 5 measurement iterations, 2 forks, single-threaded throughput mode.\n\n| Implementation                    | Throughput (ops/ms) | Bytes Allocated per UUID (B/op) | GC Alloc Rate (MB/s) |\n|-----------------------------------|---------------------|---------------------------------|----------------------|\n| **SecureRandom + ByteBuffer**     | ~4 725 (≈4.7 M/s)   | ~176 B                          | ~793 MB/s            |\n| **Optimized (ThreadLocalRandom)** | ~227 174 (≈227 M/s) | ~32 B                           | ~6 931 MB/s          |\n\n- **Throughput**\n   - *Naïve*: ~4 725 ops/ms → ≈4.7 million UUIDs per second.\n   - *Optimized*: ~227 174 ops/ms → ≈227 million UUIDs per second.\n   - Result: **≈50× faster** throughput in the optimized version.\n\n- **Bytes Allocated per UUID**\n   - *Naïve*: ~176 bytes of garbage (creates `byte[16]` + `ByteBuffer` + one `UUID`).\n   - *Optimized*: ~32 bytes of garbage (only one `UUID` object).\n   - Result: **≈82% fewer bytes** allocated per call.\n\n- **GC Allocation Rate (MB/s)**\n   - *Naïve*: ~793 MB allocated per second.\n   - *Optimized*: ~6 931 MB allocated per second (because it generates far more UUIDs).\n   - Although the optimized version allocates more in absolute MB/s, it does **not** increase per-UUID allocation—thus total throughput is massively higher and GC pauses, while more frequent, remain a small fraction of total runtime.\n\n### Observations\n\n1. **Throughput Gain**  \n   The optimized code leverages non-blocking `ThreadLocalRandom` and direct 64-bit/bitwise assembly, eliminating array and buffer overhead. The result is order-of-magnitude faster UUID generation, making it suitable for high-throughput, low-latency systems.\n\n2. **Garbage Generation**  \n   By reducing each call to a single 32-byte `UUID` allocation, the optimized approach minimizes per-call garbage. This keeps pause times short even when producing hundreds of millions of UUIDs per second.\n\n3. **GC Behavior**\n   - The naïve version triggers ~54 collections, spending ~35 ms total in GC during the measured period.\n   - The optimized version triggers ~268 collections, spending ~215 ms total in GC.\n   - In both cases, GC overhead is negligible relative to total execution time, but the optimized version still wins because it produces far more UUIDs in the same wall-clock time.\n\n\n### Benchmark\n\n| Benchmark                                           | Version                                   | Mode  | Cnt | Score       | Error       | Units   |\n|----------------------------------------------------|-------------------------------------------|-------|-----|-------------|-------------|---------|\n| UUIDV7Benchmark.benchGenerate                      | java.util.UUID                            | thrpt | 20  | 4261.388    | ± 39.561    | ops/ms  |\n| UUIDV7Benchmark.benchGenerate:gc.alloc.rate        | java.util.UUID                            | thrpt | 20  | 975.192     | ± 9.078     | MB/sec  |\n| UUIDV7Benchmark.benchGenerate:gc.alloc.rate.norm   | java.util.UUID                            | thrpt | 20  | 240.002     | ± 0.001     | B/op    |\n| UUIDV7Benchmark.benchGenerate:gc.count             | java.util.UUID                            | thrpt | 20  | 66.000      |             | counts  |\n| UUIDV7Benchmark.benchGenerate:gc.time              | java.util.UUID                            | thrpt | 20  | 32.000      |             | ms      |\n| UUIDV7Benchmark.benchGenerate                      | io.github.robsonkades:uuidv7              | thrpt | 20  | 148359.782  | ± 1159.173  | ops/ms  |\n| UUIDV7Benchmark.benchGenerate:gc.alloc.rate        | io.github.robsonkades:uuidv7              | thrpt | 20  | 4526.684    | ± 35.304    | MB/sec  |\n| UUIDV7Benchmark.benchGenerate:gc.alloc.rate.norm   | io.github.robsonkades:uuidv7              | thrpt | 20  | 32.000      | ± 0.001     | B/op    |\n| UUIDV7Benchmark.benchGenerate:gc.count             | io.github.robsonkades:uuidv7              | thrpt | 20  | 174.000     |             | counts  |\n| UUIDV7Benchmark.benchGenerate:gc.time              | io.github.robsonkades:uuidv7              | thrpt | 20  | 105.000     |             | ms      |\n| UUIDV7Benchmark.benchGenerate                      | com.github.f4b6a3:uuid-creator            | thrpt | 20  | 69965.993   | ± 117.158   | ops/ms  |\n| UUIDV7Benchmark.benchGenerate:gc.alloc.rate        | com.github.f4b6a3:uuid-creator            | thrpt | 20  | 2134.816    | ± 3.575     | MB/sec  |\n| UUIDV7Benchmark.benchGenerate:gc.alloc.rate.norm   | com.github.f4b6a3:uuid-creator            | thrpt | 20  | 32.000      | ± 0.001     | B/op    |\n| UUIDV7Benchmark.benchGenerate:gc.count             | com.github.f4b6a3:uuid-creator            | thrpt | 20  | 120.000     |             | counts  |\n| UUIDV7Benchmark.benchGenerate:gc.time              | com.github.f4b6a3:uuid-creator            | thrpt | 20  | 69.000      |             | ms      |\n| UUIDV7Benchmark.benchGenerate                      | com.fasterxml.uuid:java-uuid-generator    | thrpt | 20  | 4074.375    | ± 27.374    | ops/ms  |\n| UUIDV7Benchmark.benchGenerate:gc.alloc.rate        | com.fasterxml.uuid:java-uuid-generator    | thrpt | 20  | 1118.863    | ± 7.527     | MB/sec  |\n| UUIDV7Benchmark.benchGenerate:gc.alloc.rate.norm   | com.fasterxml.uuid:java-uuid-generator    | thrpt | 20  | 288.002     | ± 0.001     | B/op    |\n| UUIDV7Benchmark.benchGenerate:gc.count             | com.fasterxml.uuid:java-uuid-generator    | thrpt | 20  | 76.000      |             | counts  |\n| UUIDV7Benchmark.benchGenerate:gc.time              | com.fasterxml.uuid:java-uuid-generator    | thrpt | 20  | 41.000      |             | ms      |\n\n---\n\n## License\n\nThis project is licensed under the MIT License. See [LICENSE](./LICENSE) for details.\n\n## Contributing\n\nContributions, bug reports, and feature requests are always welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobsonkades%2Fuuidv7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobsonkades%2Fuuidv7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobsonkades%2Fuuidv7/lists"}