Skip to content

Read the barretenberg prover state with one jq call - #319

Merged
alxkzmn merged 1 commit into
ethereum:mainfrom
gopikannappan:barretenberg-prove-shell-overhead
Oct 28, 2026
Merged

alxkzmn merged 1 commit into
ethereum:mainfrom
gopikannappan:barretenberg-prove-shell-overhead

Conversation

@gopikannappan

@gopikannappan gopikannappan commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Read all five STATE_JSON fields with one jq invocation in barretenberg/prove.sh, reducing subprocess overhead inside the timed proving command. Emit an empty line when input-size is absent so the field reads remain aligned.

A local parsing benchmark on an M2, with 40 runs per version including Bash startup, reduced median time from 13.39 ms to 4.74 ms.

Validation: equivalent parsed output with and without input-size, and with spaces in paths, under Bash 3.2 and 5. bash -n passed.

Addresses #26 (1).

`prove.sh` is the region hyperfine times, so every subprocess it spawns is
charged to barretenberg's proving time. It parsed `STATE_JSON` with five
separate `jq` invocations, which cost about 11 ms of the ~13 ms the script
spent before reaching `nargo`.

Reading all five fields from one `jq` call takes that to about 3 ms, a median
saving of 8.65 ms per invocation measured over 40 runs on an M2. Against the
smallest published barretenberg figure -- 158.9 ms for poseidon2 at input
size 2 -- that is roughly 5% of the reported proving time.

`input-size` now falls back to the empty string rather than `empty` so the
field always occupies a line and the reads stay aligned; the resulting value
is the same empty string the old `// empty` produced, so the existing
`[[ -n "$INPUT_SIZE" ]]` branch is unchanged.

Differentially tested against the previous parsing on three inputs -- with
`input-size`, without it, and with spaces in every path -- byte-identical
output and the same exit status in each case, under both bash 5 and the
macOS system bash 3.2.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@alxkzmn alxkzmn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@alxkzmn
alxkzmn merged commit b7b08df into ethereum:main Oct 28, 2026
7 checks passed
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