---
title: "Persistent Structures: Key to 2000x Speedup in Neon’s WAL Indexing"
description: "Neon's pageserver must answer GetPage(key, LSN) by finding, for a point in key–LSN space, the first image or delta layer rectangle directly below it, across tens of millions of layers."
url: "https://swe.quest/articles/persistent-structures-key-to-2000x-speedup-in-neon-s-wal-indexing-ca3203d56783f4cb"
canonical: "https://neon.com/blog/persistent-structures-in-neons-wal-indexing"
source: "Neon"
published: "2023-05-19"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 10
tags: ["data-structures","storage-engines","postgres","rust","performance"]
---

# Persistent Structures: Key to 2000x Speedup in Neon’s WAL Indexing

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-05-19, 10 min read, Deep dive. Original: [https://neon.com/blog/persistent-structures-in-neons-wal-indexing](https://neon.com/blog/persistent-structures-in-neons-wal-indexing)

## Summary

Neon's pageserver must answer GetPage(key, LSN) by finding, for a point in key–LSN space, the first image or delta layer rectangle directly below it, across tens of millions of layers. Linear scans and R-trees degrade to O(N), and a 2D segment tree would need balancing and lazy propagation that blow the complexity budget. Neon instead precomputes a "layer coverage" BST for the latest LSN and makes it persistent (copy-on-write) with the rpds crate, inserting layers bottom-up so every historical LSN has its own queryable version. Construction and space are O(N log N), queries are O(log N), and the result is 70x faster than the R-tree on real databases and 2000x on larger synthetic ones.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Data structures](https://swe.quest/tags/data-structures.md) (Architecture & design)
- [Storage engines](https://swe.quest/tags/storage-engines.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Rust](https://swe.quest/tags/rust.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- binary search trees ([easy posts on Search](https://swe.quest/tags/search.md?difficulty=easy))
- big-O complexity
- write-ahead logging ([easy posts on Observability](https://swe.quest/tags/observability.md?difficulty=easy))
- LSM-style layered storage ([easy posts on Storage engines](https://swe.quest/tags/storage-engines.md?difficulty=easy))

## Keywords

Neon, rpds, R-tree, segment tree, persistent data structures, WAL

## Related posts

- [Deep dive into Neon storage engine](https://swe.quest/articles/deep-dive-into-neon-storage-engine-efc0ffc53406f34d.md): Neon · 2023-03-30 · Hard · 7 min read · Storage engines, PostgreSQL, Distributed databases, Serverless, Replication
  Neon's storage engine separates Postgres compute from storage and serves pages through GetPage@LSN, reconstructing any page as of any log sequence number from immutable layer files.
- [WAL + S3: Lakebase storage for the era of agents](https://swe.quest/articles/wal-s3-lakebase-storage-for-the-era-of-agents-3f04922da0e40ff3.md): Neon · 2026-08-24 · Hard · 15 min read · PostgreSQL, Storage engines, Storage systems, Data structures, Replication
  Lakebase Postgres (Neon's architecture) treats the Postgres write-ahead log as the source of truth and data pages as a derived cache, splitting the system into stateless compute running unmodified Postgres and a storage layer of Paxos-replicated safekeepers, pageservers, and S3.
- [A Deep Dive Into Neon’s Instant PITR](https://swe.quest/articles/a-deep-dive-into-neon-s-instant-pitr-6efa2ca3d55740a4.md): Neon · 2025-03-26 · Medium · 6 min read · PostgreSQL, Storage engines, Databases
  Neon's point-in-time restore is instant because its storage is copy-on-write: compute nodes stream WAL to Paxos-replicated safekeepers, and pageservers reconstruct any page at any past LSN from image and delta layers kept in object storage.
- [Lakebase Search: vector and BM25 on Neon](https://swe.quest/articles/lakebase-search-vector-and-bm25-on-neon-b760351851c96b48.md): Neon · 2026-07-02 · Medium · 7 min read · Vector search, Search, PostgreSQL, Storage engines
  Neon's Lakebase Search adds two Postgres extensions, lakebase\_vector (IVF partitioning plus RaBitQ quantization, pgvector-compatible) and lakebase\_text (a BM25-native index with Block-Max WAND top-K pushdown), designed for Neon's separated compute and object-storage tiers.
- [Everyone gets faster writes: We turned off FPW's in Neon](https://swe.quest/articles/everyone-gets-faster-writes-we-turned-off-fpw-s-in-neon-60d0cd25f29077e7.md): Neon · 2026-05-07 · Hard · 7 min read · PostgreSQL, Storage engines, Performance engineering, Distributed databases
  Neon disabled Postgres full-page writes fleet-wide because its stateless compute streams WAL to a Paxos safekeeper quorum and has no local disk pages that can tear.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
