Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace libwebsockets with libuv + picohttpparser
Summary
Replace the libwebsockets HTTP server backend with libuv TCP + picohttpparser, improving HTTP throughput from 3,600 req/s to 15,571 req/s (4.3x).
lws-bridge.cto use libuv for TCP and picohttpparser for zero-copy HTTP parsing, keeping the same C API (lws_bridge_serve,lws_bridge_ws_send,lws_bridge_ws_broadcast) so the LLVM IR codegen needs zero changeshttpServe()now runs onuv_default_loop()instead of its ownlws_service()loop, fixing the bug wherehttpServe()andsetTimeout()couldn't coexistsnprintfwith memcpy of static header prefixes + fast itoa, shrinkhttp_conn_tfrom ~1MB to ~15KB by heap-allocating the request body on demandBenchmark results
50 concurrent connections, 10s duration, Hello World handler.
Files changed
c_bridges/lws-bridge.cbench/http/c-server.cscripts/build-vendor.shsrc/compiler.ts-lwebsockets, add picohttpparser.o, addusesMongooseto libuv condition)src/native-compiler-lib.tssrc/codegen/llvm-generator.tsusesMongoosetoneedsLibuvcondition.github/workflows/ci.ymldocs/public/benchmarks.jsonTest plan
npm test— 168/168 tests passnode --import tsx --test tests/http-routes.test.ts— 16/16 HTTP tests pass (routes, POST body, query params, status codes, deflate, zstd, concurrent requests, keepalive)npm run verify:quick— self-hosting passes (Stage 0 + Stage 1)bash bench/run-http.sh— benchmark confirms improvement