A high-performance JavaScript Sequential GUID Generator that creates sortable, unique identifiers with microsecond precision.
- High Performance: Optimized for speed with minimal memory allocations
- Microsecond Precision: Uses high-resolution timestamps for better uniqueness
- Sortable: GUIDs are chronologically sortable
- Collision Resistant: Multiple entropy sources and a counter for high-frequency generation
- RFC4122 Compliant: Generates valid UUID v4 format
- Zero Dependencies: Only requires moment.js for date calculations
npm install jscombguid
import generateSequentialGuid from 'jscombguid';
// Generate a single GUID
const guid = generateSequentialGuid();
console.log(guid); // e.g., "550e8400-e29b-41d4-a716-446655440000"
// Generate multiple GUIDs
const guids = Array.from({ length: 10 }, () => generateSequentialGuid());
The generator is optimized for high-performance scenarios:
- Average generation time: < 0.1ms per GUID
- Can generate 100,000+ unique GUIDs per second
- Memory efficient with minimal allocations
- Stable performance under load
The generator creates sequential GUIDs by combining:
- A base UUID (24 characters)
- Days since 1900-01-01 (4 characters)
- Microseconds since start of day (8 characters)
- A 16-bit counter for high-frequency generation (4 characters)
This combination ensures:
- Chronological sortability
- High uniqueness
- Microsecond precision
- Collision resistance
const iterations = 100000;
const start = process.hrtime();
for (let i = 0; i < iterations; i++) {
generateSequentialGuid();
}
const [seconds, nanoseconds] = process.hrtime(start);
const averageTime = (seconds * 1000 + nanoseconds / 1000000) / iterations;
console.log(`Average generation time: ${averageTime.toFixed(3)}ms`);
# Install dependencies
npm install
# Run tests
npm test
# Run linting
npm run lint
# Build
npm run build
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Original concept inspired by this StackOverflow discussion
- Thanks to @thetinomen for code improvements