Skip to content

triedb/pathdb: improve the performance of parse index block#32219

Merged
rjl493456442 merged 2 commits intoethereum:masterfrom
jsvisa:pathdb-parse-block
Jul 17, 2025
Merged

triedb/pathdb: improve the performance of parse index block#32219
rjl493456442 merged 2 commits intoethereum:masterfrom
jsvisa:pathdb-parse-block

Conversation

@jsvisa
Copy link
Copy Markdown
Contributor

@jsvisa jsvisa commented Jul 16, 2025

The implementation of parseIndexBlock used a reverse loop with slice appends to build the restart points, which was less cache-friendly and involved unnecessary allocations and operations. In this PR we change the implementation to read and validate the restart points in one single forward loop.

Here is the benchmark test:

go test -benchmem -bench=BenchmarkParseIndexBlock ./triedb/pathdb/

The result as below:

benchmark                      old ns/op     new ns/op     delta
BenchmarkParseIndexBlock-8     52.9          37.5          -29.05%

about 29% improvements

jsvisa added 2 commits July 16, 2025 16:35
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
@jsvisa jsvisa requested a review from rjl493456442 as a code owner July 16, 2025 08:41
@rjl493456442
Copy link
Copy Markdown
Member

IIUC, the performance speedup comes from the 1-loop traversal, instead of 2 right?

@rjl493456442 rjl493456442 added this to the 1.16.2 milestone Jul 17, 2025
@rjl493456442 rjl493456442 merged commit a487729 into ethereum:master Jul 17, 2025
3 of 5 checks passed
@jsvisa jsvisa deleted the pathdb-parse-block branch July 25, 2025 01:15
howjmay pushed a commit to iotaledger/go-ethereum that referenced this pull request Aug 27, 2025
…#32219)

The implementation of `parseIndexBlock` used a reverse loop with slice
appends to build the restart points, which was less cache-friendly and
involved unnecessary allocations and operations. In this PR we change
the implementation to read and validate the restart points in one single
forward loop.

Here is the benchmark test:

```bash
go test -benchmem -bench=BenchmarkParseIndexBlock ./triedb/pathdb/
```

The result as below:

```
benchmark                      old ns/op     new ns/op     delta
BenchmarkParseIndexBlock-8     52.9          37.5          -29.05%
```

about 29% improvements

---------

Signed-off-by: jsvisa <delweng@gmail.com>
gballet pushed a commit to gballet/go-ethereum that referenced this pull request Sep 11, 2025
…#32219)

The implementation of `parseIndexBlock` used a reverse loop with slice
appends to build the restart points, which was less cache-friendly and
involved unnecessary allocations and operations. In this PR we change
the implementation to read and validate the restart points in one single
forward loop.

Here is the benchmark test:

```bash
go test -benchmem -bench=BenchmarkParseIndexBlock ./triedb/pathdb/
```

The result as below:

```
benchmark                      old ns/op     new ns/op     delta
BenchmarkParseIndexBlock-8     52.9          37.5          -29.05%
```

about 29% improvements

---------

Signed-off-by: jsvisa <delweng@gmail.com>
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.

2 participants