Skip to content

Send Bind/Execute/Sync in one write - #1384

Open
sideeffffect wants to merge 2 commits into
typelevel:mainfrom
sideeffffect:pipeline-bind-execute
Open

sideeffffect wants to merge 2 commits into
typelevel:mainfrom
sideeffffect:pipeline-bind-execute

Conversation

@sideeffffect

@sideeffffect sideeffffect commented Oct 29, 2026 •

Copy link
Copy Markdown

Adds a new method to send FrontendMessages in bulk. Enables lowering the number of writes and thus increasing efficiency.

sideeffffect and others added 2 commits October 30, 2026 00:47
Every `MessageSocket#send` was its own socket write, so a warm
parameterized command (Bind, Execute, Sync) cost three writes and,
with TCP_NODELAY, up to three TCP segments. A lone Flush was also
written when the statement was already parsed and described.

Add `MessageSocket#sendAll`, which encodes the messages and writes them
at once, and use it wherever messages go out back to back before a
read: Bind+Execute+Sync/Flush, Parse+Describe+Flush, Bind+Flush,
Execute+Flush and Close+Flush. Skip the Flush when Parse and Describe
are both cached, as nothing is sent and no reply is read.

ExchangeCountTest now asserts writes too: one write per exchange for
every operation kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JMH benchmark of a warm parameterized query (`unique`) and command
(`execute`) on a single session, so each operation is one
Bind/Execute/Sync exchange. Needs the docker-compose Postgres.

Results, `bench/Jmh/run -i 10 WarmSessionBench` (1 fork, 5x5s warmup,
10x5s measurement), local Postgres 11 in Docker, JDK 21, ops/s:

| Benchmark   | main (1045d3b) | this branch     | change |
|-------------|-----------------|-----------------|--------|
| warmCommand |  9930 +- 206    | 11977 +- 335    |  +21%  |
| warmQuery   | 10623 +- 350    | 13769 +- 343    |  +30%  |

A second branch run gave 11765 +- 510 and 13663 +- 406. Load average
was 3 to 6 during the runs quoted. A main run with load average 8 to 11
was too noisy to use (5807 +- 3013 and 9780 +- 1561).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sideeffffect
sideeffffect marked this pull request as ready for review October 30, 2026 16:35

This branch has not been deployed

No deployments
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