See technical specification: TASKS.md Original project URL: metarhia/metautil/tree/gsid-ai
- Unit Tests: ✅ All 6 tests passing
- Performance Tests: ✅ All 3 tests passing
- TypeScript: ✅ Compilation successful
- Integration: ✅ Added to metautil exports
- Target: 1M+ IDs/second → Achieved: 9.1M IDs/second (910% of target)
- Target: Sub-millisecond latency → Achieved: ~0.11ms per ID
- Target: Memory < 500MB for 1M IDs → Achieved: 37.0MB (well within target)
- Target: Zero collisions → Achieved: 0% collision rate in 1M samples
- Random Prefetcher: Uses existing lib/crypto.randomPrefetcher for high-performance random generation
- Bitwise Operations: Uses
& 0x3finstead of% 64for modulo operations - Pre-generated Arrays: Character lookup table for fast access
- Buffer Optimization: Optimized buffer size (24 * 1024 bytes)
- String Concatenation: Efficient string building for 24-character IDs
- Subbuffer approach: Return 24 bytes at once instead of single bytes
- Validation Utilities: ID parsing and validation functions
- Documentation: API docs, migration guides, best practices
- Browser Support: Web-compatible version
- Security Audit: Penetration testing and vulnerability assessment
| Algorithm | ID Size (chars) | Bits of Uniqueness | Sortable | Generation Speed | Collision Resistance | Use Cases |
|---|---|---|---|---|---|---|
| UUID v4 | 36 | 122 bits | No | Medium | Very High | General purpose, distributed systems |
| UUID v1 | 36 | 122 bits | Yes (time-based) | Medium | Very High | Time-ordered data, logs |
| ULID | 26 | 128 bits | Yes (time-based) | High | Very High | Databases, logs, sorting |
| Nano ID | 21 | 126 bits | No | High | Very High | URLs, short identifiers |
| CUID | 25 | 112 bits | Yes (time-based) | High | High | Web applications |
| Snowflake ID | 19 | 63 bits | Yes (time-based) | Very High | High | Twitter, distributed databases |
| generateKey | 24 | 144 bits | No | Low | Very High | Custom key generation |
| Proposed GSID | 24 | 144 bits | No | Very High | Very High | High-performance systems |
| Algorithm | Duration (ms) | Rate (IDs/sec) | Memory per ID |
|---|---|---|---|
| GSID | 110.00 | 10,160,864 | ~39 bytes |
| UUID v4 | 136.36 | 7,333,738 | ~36 bytes |
| Nano ID | 306.78 | 3,259,613 | ~21 bytes |
| CUID | 421.38 | 2,373,163 | ~25 bytes |
| generateKey | 1035.54 | 965,676 | ~24 bytes |
- 33% shorter than UUID (24 vs 36 chars)
- 24% faster than UUID (9.1M vs 7.3M IDs/sec)
- Higher entropy than UUID (144 vs 122 bits)
- URL-safe characters (no encoding needed)
- Non-sortable design (optimized for speed)
- 841% faster than generateKey with same length and entropy
- Excellent memory efficiency (39 bytes per ID)
- Non-sortable (no time-based ordering)
| Use Case | Recommended Algorithm | Reasoning |
|---|---|---|
| High-performance APIs | GSID | Best speed/size ratio |
| Database primary keys | GSID | Shorter than UUID, high entropy |
| URL parameters | GSID | URL-safe, compact |
| Time-ordered logs | ULID | Sortable, high entropy |
| General purpose | UUID v4 | Widely supported |
| Custom key generation | generateKey | Flexible character sets |