Skip to content

Conversation

@Tabaie
Copy link
Contributor

@Tabaie Tabaie commented Sep 17, 2025

This PR introduces a simple memory pool to massively reduce the number of heap allocations of single field elements introduced by the new GKR API.

On the benchmark std/hash/mimc/gkr-mimc/BenchmarkMerkleTree and a similar one for the gkr-mimc currently on the Linea monorepo, with an hpc6a.48xlarge instance, we get:

This PR: 3937 MB
feat/gkr/hashes: 20292 MB (5.15x improvement)
linea-monorepo@main: 7229 MB (1.83x improvement)

@Tabaie Tabaie changed the base branch from master to feat/gkr/hashes September 17, 2025 19:21
@Tabaie Tabaie requested a review from Copilot September 17, 2025 20:48
@Tabaie Tabaie marked this pull request as ready for review September 17, 2025 20:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves memory usage in GKR implementation by introducing a memory pool for field elements to reduce heap allocations. The optimization achieves significant memory reduction: from 20292 MB to 4403 MB (4.6x improvement) on benchmarks.

Key changes include:

  • Implementation of a synchronous memory pool system in gateAPI to reuse field element allocations
  • Replacement of global API instances with local instances across all curve implementations
  • Simplification of test benchmarks by removing complex file caching logic

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
std/hash/mimc/gkr-mimc/gkr-mimc_test.go Renamed circuit types and simplified benchmark by removing file caching
std/permutation/gkr-mimc/gkr-mimc_test.go Renamed circuit types for consistency
internal/gkr/*/gkr.go Added memory pool to gateAPI with element allocation/deallocation methods
internal/gkr/*/gate_testing.go Updated to use local gateAPI instances
internal/gkr/*/solver_hints.go Added local gateAPI instances with proper cleanup
internal/generator/backend/template/gkr/*.tmpl Updated templates to generate optimized code

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Tabaie Tabaie requested a review from ivokub September 17, 2025 20:56
@ivokub ivokub mentioned this pull request Sep 18, 2025
12 tasks
@ivokub ivokub added type: perf feat: gkr PRs related to GKR labels Sep 18, 2025
@Tabaie Tabaie marked this pull request as draft September 22, 2025 21:21
@Tabaie
Copy link
Contributor Author

Tabaie commented Sep 24, 2025

Closed in favor of #1616

@Tabaie Tabaie closed this Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: gkr PRs related to GKR type: perf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants