Skip to content

Use string concat instead of format#1

Closed
gzuidhof wants to merge 3 commits intomainfrom
minor
Closed

Use string concat instead of format#1
gzuidhof wants to merge 3 commits intomainfrom
minor

Conversation

@gzuidhof
Copy link

I believe this is faster.. but who knows, benchmarks on my device are all over the place as my environment isn't consistent at all 😅 - so do give it a run yourself!

Using string concat (new)

% just benchmark --skip-single -d 20s

--------------------------------------------------------------------
MULTI-THREAD BENCHMARK (8 threads)
--------------------------------------------------------------------

Test         reqs/sec    % baseline   avg (ms)   p95 (ms)   p99 (ms)
--------------------------------------------------------------------
Baseline        24958           100       0.36       0.85       3.31
Lua (noop)      23560            94       0.44       1.24       5.43
JA4             22230            89       0.67       1.94       8.51

Using string formatting (old)

% just benchmark --skip-single -d 20s

--------------------------------------------------------------------
MULTI-THREAD BENCHMARK (8 threads)
--------------------------------------------------------------------

Test         reqs/sec    % baseline   avg (ms)   p95 (ms)   p99 (ms)
--------------------------------------------------------------------
Baseline        27374           100       0.36       0.73       3.33
Lua (noop)      23661            86       1.15       2.67      14.82
JA4             20345            74       0.42       0.85       3.90

@gzuidhof gzuidhof requested a review from jamielinux January 26, 2026 17:05
@gzuidhof
Copy link
Author

Note how far apart my baselines are.. yeah..

the implementation. Integration tests run TLS clients (curl, Chromium, uTLS) to
connect to haproxy containers and provide end-to-end validation.

You will need to have `just` >=2.0.0 and `busted` installed.
Copy link
Member

Choose a reason for hiding this comment

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

Unless I'm going crazy, I don't think just >= 2.0.0 exists?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I spotted I'm using a feature that was introduced in 1.46.0.

@jamielinux
Copy link
Member

-- String concatenation is faster than string.format in LuaJIT

Haproxy doesn't use LuaJIT, but string concat should still be faster than string.format with normal Lua because multiple .. get compiled into a single OP_CONCAT instruction that just sums lengths and copies, skipping the per-specifier format string parsing that string.format does.

fingerprint_prefix is only once-per-request (whereas the existing hex lookup table is many-per-request). So there might be a small performance benefit to using string concat but I imagine it's probably <1%.

Still, I think the code looks nicer with string concat instead of string.format! I'll close this PR and implement a similar string concat but without type coercion and using fewer concat operands.

@jamielinux jamielinux closed this Feb 9, 2026
@jamielinux jamielinux deleted the minor branch February 9, 2026 13:59
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