A high-performance, memory-efficient offline timezone lookup library for TypeScript using a custom binary format and quadtree spatial indexing.
This library uses GeoJSON data from timezone-boundary-builder.
- Fast: Performs 49-52 million lookups per second (~19-21ns per op) on an Apple M4 Pro CPU.
- Tiny Memory Footprint: Operates directly on raw binary data (ArrayBuffer/Uint8Array). Memory usage is limited to the LLTZ binary file size (approximately 12MiB), with no additional object overhead.
- Zero Dependencies: A lightweight, standalone TypeScript library with no external runtime dependencies.
- Universal: Runs in both server (Node.js, Bun) and client (browser) environments.
- High Accuracy: Validated to match
geo-tzresults in >99.99% of cases.
The benches directory contains performance benchmarks comparing lltz with geo-tz. These are the performance numbers obtained on Node 24.22.3 on an Apple M4 Pro CPU.
$ pnpm bench noop:all lltz:all geo-tz:all
┌─────────┬─────────────────────────────────────────────┬───────────────────┬────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼─────────────────────────────────────────────┼───────────────────┼────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ 'noop: all: 1000x <random>' │ '4349.7 ± 0.30%' │ '4209.0 ± 43.00' │ '233944 ± 0.02%' │ '237586 ± 2452' │ 229902 │
│ 1 │ 'noop: all: 1000x <random> in central US' │ '4263.6 ± 0.26%' │ '4166.0 ± 82.00' │ '238587 ± 0.03%' │ '240038 ± 4744' │ 234545 │
│ 2 │ 'lltz: all: 1000x <random>' │ '20980 ± 0.26%' │ '20500 ± 1250.0' │ '48514 ± 0.09%' │ '48780 ± 2978' │ 47665 │
│ 3 │ 'lltz: all: 1000x <random> in central US' │ '19366 ± 0.23%' │ '19042 ± 1083.0' │ '52418 ± 0.08%' │ '52515 ± 3030' │ 51638 │
│ 4 │ 'geo-tz: all: 1000x <random>' │ '1443275 ± 5.72%' │ '1087208 ± 413917' │ '995 ± 3.82%' │ '920 ± 390' │ 693 │
│ 5 │ 'geo-tz: all: 1000x <random> in central US' │ '304032 ± 0.97%' │ '294584 ± 14167' │ '3373 ± 0.36%' │ '3395 ± 165' │ 3290 │
└─────────┴─────────────────────────────────────────────┴───────────────────┴────────────────────┴────────────────────────┴────────────────────────┴─────────┘
lltz is roughly 53x faster than geo-tz for random lookups in the entire world and 15x faster for random lookups in the central US. The noop rows measure the benchmark loop and random number generation alone.
$ pnpm bench:memory
lltz: all
Δ time: 29.217 ms
Δ rss: 23.422 MiB
Δ heapTotal: 3.500 MiB
Δ heapUsed: 1.615 MiB
Δ external: 9.248 MiB
Δ arrayBuffers: 9.188 MiB
geo-tz: all
Δ time: 1564.550 ms
Δ rss: 1638.547 MiB
Δ heapTotal: 1579.344 MiB
Δ heapUsed: 1484.988 MiB
Δ external: -1.778 MiB
Δ arrayBuffers: -1.838 MiB
Loading the data from disk and then querying 1 million random points is 53x faster with lltz than with geo-tz and uses 70x less memory.
pnpm add lltz # or npm, yarn, bunThe timezones.lltz file included in the NPM package contains all three data variants described in the timezone-boundary-builder README: all (timezones.geojson, the default, with the most comprehensive coverage), 1970 (timezones-1970.geojson) and now (timezones-now.geojson). Pick one when creating the lookup:
Lltz.make('now') // lltz/server
Lltz.make(buffer, 'now') // lltzimport * as Lltz from 'lltz/server'
const lookup = Lltz.make() // Automatically loads the built-in timezones.lltz file
// ↳ or Lltz.make('1970')
const timezones = lookup(40.7128, -74.006) // New York
console.log(timezones) // ['America/New_York']To load the data yourself, for example from a custom path or a file you built with make, use make from lltz with the file's bytes. make from lltz/server always loads the built-in file:
import fs from 'node:fs'
import * as Lltz from 'lltz'
const buffer = fs.readFileSync(new URL(import.meta.resolve('lltz/data/timezones.lltz')))
// ↳ or fs.readFileSync('node_modules/lltz/data/timezones.lltz')
const lookup = Lltz.make(buffer)
const timezones = lookup(40.7128, -74.006) // New York
console.log(timezones) // ['America/New_York']import * as Lltz from 'lltz'
const response = await fetch('/path/to/timezones.lltz')
const arrayBuffer = await response.arrayBuffer()
const lookup = Lltz.make(arrayBuffer)
console.log(lookup(40.7128, -74.006)) // ['America/New_York']The LLTZ binary file format is designed for efficient querying on raw bytes. It consists of the following sections:
- Header: The first eight bytes are
LLTZ3\0\0\0. - Timezone Strings: The byte length as a
u16, followed by the sorted timezone IDs separated by null bytes. - Variant Mappings: For each variant (
all,1970,now), au16per timezone with the index of the timezone ID it maps to in that variant. - Grid Index: A 180x360 grid of
u32cells, one per 1-degree square, for O(1) access. The top 2 bits mark a cell as empty (ocean), a single timezone, a leaf or a quadtree node, and the low 30 bits hold the timezone index or the offset of the leaf or node. - QuadTree Nodes: One byte of 2-bit tags for the four children, followed by bit-packed references to the non-empty ones: a timezone index for a single-timezone child, or a 24-bit offset for a leaf or node. The builder merges a subtree into one leaf when that is smaller and still cheap to decode. Identical nodes and leaves are stored once.
- Leaves: Up to 8 timezones and the boundary chains that cross the cell, all bit-packed. Each chain is a polyline in coordinates relative to the cell's corner, stored once with bitmasks of the timezones it bounds, so an edge between two timezones is not stored twice. Edges along the cell's border are dropped. Points are stored as zigzag-encoded second differences, written as subexponential codes with a per-chain parameter.
- Builder (Python): Normalizes
timezone-boundary-builderGeoJSON files to a 1,000,000 scale grid and builds a quadtree up to 4 levels deep (1/16-degree cells) under each grid cell. - Runtime (TypeScript): Performs an initial O(1) lookup using the grid. For points near boundaries, it walks the quadtree to a leaf and casts a ray against the leaf's chains as it decodes them, with no allocations. Oceans default to
Etc/GMToffsets based on 15-degree longitude bands.
To download the latest GeoJSON data and convert it into the optimized LLTZ binary format, run:
Requires uv to be installed.
make -jTest lookup results against the geo-tz package:
pnpm testBenchmark performance against the geo-tz package:
pnpm benchBenchmark memory usage against the geo-tz package:
pnpm bench:memoryMIT for the code, ODbL for the data.