Skip to content

libmicrohttpd 1.0.10: header values parsed in a tight loop (a JWT costs a third) - #27

Merged
kzangeli merged 1 commit into
mainfrom
perf/mhd-header-value-fastpath
Oct 13, 2026
Merged

kzangeli merged 1 commit into
mainfrom
perf/mhd-header-value-fastpath

Conversation

@kzangeli

@kzangeli kzangeli commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

tools/mhd/patches/1.0.10/0001-header-value-fastpath.patch - applied by mhdBuild.sh (CI image, published image, runners, workstations).

Why: profiling coraine's PATCH with an access token, the token's cost is MHD's header parser: get_req_header() reads a value one character at a time, re-testing CR/LF/SP/HTAB/NUL and writing ws_start back to the connection for each. get_req_headers went from 2.0 % to 9.2 % of the broker's time with a 696-byte Authorization: Bearer <JWT>.

The patch: after a value's first character, the following characters above SP are processed exactly as it is - they are skipped in a compare-only loop. CR, LF, SP, HTAB, NUL and other control characters stop it and take MHD's path unchanged (line end, obs-fold, bare CR/LF, the client discipline levels). Under MHD_FAVOR_SMALL_CODE the release's code is compiled.

Measured (coraine on 1 core, corDB, PATCH c50, ABBA stock/patched/patched/stock, 12 s each):

stock 1.0.10 patched
no header 108.6k / 107.1k 107.5k / 107.2k
696-byte token, no plugin 99.4k / 98.1k 104.6k / 103.4k
token cost −8.5 % (0.86 µs) −3.2 % (0.31 µs)

libmicrohttpd's own make check on the patched tree: 180 of 180 pass. coraine's functests on it (debug build, mongoc, the patched library through LD_LIBRARY_PATH, verified in a running broker's maps): 811 of 811 pass (2026-10-13, after the merge).

Upstream: not posted - a draft for Karlson2k/libmicrohttpd waits for KZ.

Merge after: nothing

🤖 Generated with Claude Code

…e tight loop

A 700-byte Authorization header cost 0.86 us of a 10 us PATCH in get_req_headers; with the patch 0.31 us.
Line ends, folding, bare CR/LF and the client discipline levels go through MHD's loop as before;
libmicrohttpd's make check: 180/180.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kzangeli
kzangeli merged commit 909ad1d into main Oct 13, 2026
1 check passed
@kzangeli
kzangeli deleted the perf/mhd-header-value-fastpath branch October 13, 2026 15:02
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