ant.lockb) that provides faster parsing and smaller file sizes compared to JSON-based lockfiles.
Overview
Theant.lockb lockfile:
- Binary format - Compact, structured binary data
- Memory-mapped - Instant loading via mmap on Unix, optimized reading on Windows
- Deterministic - Same dependencies always produce identical lockfile
- Fast lookups - Hash table for O(1) package name lookups
- Version controlled - Can be committed to git (binary-safe)
File Structure
Header Structure
0x504B474C (“PKGL” in ASCII) identifies the file format.
Version: Currently 1. Future versions may introduce breaking changes.
Package Structure
Each package is stored as a 136-byte struct:Package Flags
Version Storage
Versions are stored as separate integers for efficient comparison:Integrity Hash
SHA-512 integrity hash (64 bytes) for tarball verification:sha512-... format.
Dependency Structure
Dependency Flags
String Table
All strings (package names, URLs, constraints, etc.) are stored in a deduplicated string table:- Deduplication: Common strings stored once
- Fast access: Direct offset-based lookups
- Compact: No null terminators or delimiters needed
Hash Table
For fast package lookups by name:package_index = 0xFFFFFFFF
Lockfile Generation
When Ant generates a lockfile:- Resolve - Resolve all dependencies to exact versions
- Collect - Gather all packages and their dependencies
- Intern strings - Build deduplicated string table
- Sort - Sort packages for deterministic output
- Build hash table - Create hash table for fast lookups
- Write - Write all sections to file
ant.lockb containing:
- Header
- 15 packages (lodash + express + their dependencies)
- 42 dependency edges
- String table with ~30 unique strings
- Hash table with ~32 buckets
Reading Lockfile
Ant reads lockfiles using memory-mapped I/O for instant access: Unix (mmap):Lockfile Updates
The lockfile is updated when:ant add <package>- Adds new packagesant remove <package>- Removes packagesant update- Updates to latest compatible versionsant install(no lockfile) - Generates new lockfile
- Read existing lockfile (if present)
- Apply changes (add/remove/update)
- Re-resolve affected dependencies
- Write new lockfile
package.json + same registry state = identical lockfile
Version Control
Should you commit ant.lockb? ✅ Yes, for:- Applications
- Services
- End-user projects
- Libraries (usually)
- Packages published to npm
- Reproducible builds - Everyone gets same versions
- CI/CD consistency - Same versions in all environments
- Debugging - Know exact versions that caused issues
Lockfile Validation
Ant validates lockfiles on load:- Magic number - Verify file format
- Version - Check format version compatibility
- Bounds - Verify all offsets are within file
- Integrity - Validate package integrity hashes
Comparison with Other Lockfiles
| Feature | ant.lockb | package-lock.json | yarn.lock |
|---|---|---|---|
| Format | Binary | JSON | YAML-like |
| Size | ~50KB | ~500KB | ~300KB |
| Parse time | ~1ms | ~50ms | ~100ms |
| Memory usage | Zero-copy mmap | Full parse | Full parse |
| Hash lookup | O(1) | O(n) | O(n) |
| Deterministic | ✅ Yes | ✅ Yes | ✅ Yes |
| Human readable | ❌ No | ✅ Yes | ✅ Yes |
- 10-50x faster parsing
- 10x smaller file size
- Zero-copy memory mapping
- O(1) package lookups
- Not human-readable
- Requires specialized tools to inspect
- Merge conflicts harder to resolve
Inspecting Lockfiles
Useant why to inspect lockfile contents:
Lockfile Migration
Converting from other lockfiles: From npm:package.json and generates a fresh lockfile.
Technical Details
Alignment
Structs are naturally aligned:- Header: 8-byte aligned
- Package: 8-byte aligned (136 bytes)
- Dependency: 4-byte aligned
- HashBucket: 4-byte aligned
Endianness
Lockfiles use native endianness (usually little-endian on modern systems). Note: Lockfiles are not portable across different-endian systems (rare issue).File Size
Typical lockfile sizes:| Project Size | Packages | Lockfile Size |
|---|---|---|
| Small | 10-50 | 5-20 KB |
| Medium | 100-500 | 20-100 KB |
| Large | 500-2000 | 100-500 KB |
| Huge | 2000+ | 500 KB - 2 MB |
Performance
Parsing benchmarks:| Operation | ant.lockb | package-lock.json |
|---|---|---|
| Open + parse | 1ms | 50ms |
| Lookup package | <0.1ms | 5ms |
| Memory usage | 0 (mmap) | 10-50 MB |
Future Enhancements
Planned improvements:- Compression for string table
- Package metadata caching
- Incremental updates
- Cross-endian support
- Lockfile merging tools
- Human-readable export/import