Skip to content

refactor: only unmarshal a single page from the tx index#3008

Open
evan-forbes wants to merge 2 commits into
mainfrom
evan/main/tx-search-page-only-unmarshal
Open

refactor: only unmarshal a single page from the tx index#3008
evan-forbes wants to merge 2 commits into
mainfrom
evan/main/tx-search-page-only-unmarshal

Conversation

@evan-forbes
Copy link
Copy Markdown
Member

Forward-port of #2962 (which targets v0.39.x-celestia) onto main.


The current tx_search path applies pagination too late:

  1. rpc/core/tx.goenv.TxIndexer.Search(ctx.Context(), q) returns the fully materialized []*abci.TxResult.
  2. state/txindex/kv/kv.go — accumulates filteredHashes as an unbounded map[string][]byte.
  3. state/txindex/kv/kv.go — calls txi.Get(h) for every matching hash, which proto-unmarshals the full TxResult.
  4. rpc/core/tx.go — sorts the entire slice.
  5. rpc/core/tx.go — applies per_page only after the full unmarshal+sort.

Pyroscope shows this exact path dominating memory:inuse_space: TxSearch, TxIndex.Get, TxResult.Unmarshal, ExecTxResult.Unmarshal, Event.Unmarshal, EventAttribute.Unmarshal.

Per-row cost: a TxResult is typically 1-10 KB unmarshalled. A lightweight ref (hash, height, index, eventSeq) is ~40-50 B. For a 1M-match query: ~1-10 GB → ~40-50 MB intermediate.

Tracked in https://linear.app/celestia/issue/PROTOCO-1572/oom-from-celestia-core-w-many-txsearch-queries.

@evan-forbes evan-forbes requested a review from a team as a code owner May 4, 2026 03:42
@evan-forbes evan-forbes requested review from vgonkivs and removed request for a team May 4, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant