From 604eee400eef6d7157b73fb0e4ee9cc3cb9ab9b1 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Wed, 11 Mar 2026 19:50:37 -0700 Subject: [PATCH] perf: raise default max frame size to 64 KiB --- lib/config.ml | 4 ++-- lib/h2.mli | 2 +- lib_test/test_h2_client.ml | 7 ++++++- lib_test/test_h2_server.ml | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/config.ml b/lib/config.ml index 930429e..46b546d 100644 --- a/lib/config.ml +++ b/lib/config.ml @@ -45,7 +45,7 @@ type t = let default = { (* This is effectively MAX_FRAME_SIZE, because the parser commits the frame * header to prevent backtracking, therefore the entire payload can fit the - * read buffer. The default is 16384, and can't be lower than that. + * read buffer. The default is 65536, and can't be lower than 16384. * * Note: h2 does not check that MAX_FRAME_SIZE is lower than 16384 * octets. In the case that a lower value than permitted is set, peers will @@ -57,7 +57,7 @@ let default = * The initial value is 2^14 (16,384) octets. The value advertised by an * endpoint MUST be between this initial value and the maximum allowed * frame size (2^24-1 or 16,777,215 octets), inclusive. *) - read_buffer_size = Settings.default.max_frame_size + read_buffer_size = 0x10000 ; (* Buffer size for request bodies *) request_body_buffer_size = 0x1000 ; (* Buffer size for response bodies *) response_body_buffer_size = 0x1000 ; enable_server_push = true diff --git a/lib/h2.mli b/lib/h2.mli index e624492..4f86cf8 100644 --- a/lib/h2.mli +++ b/lib/h2.mli @@ -665,7 +665,7 @@ module Config : sig type t = { read_buffer_size : int (** [read_buffer_size] specifies the size of the largest frame payload that - the sender is willing to receive, in octets. Defaults to [16384] *) + the sender is willing to receive, in octets. Defaults to [65536] *) ; request_body_buffer_size : int (** Defaults to [4096] *) ; response_body_buffer_size : int (** Defaults to [4096] *) ; enable_server_push : bool (** Defaults to [true] *) diff --git a/lib_test/test_h2_client.ml b/lib_test/test_h2_client.ml index 9156d8c..7b58455 100644 --- a/lib_test/test_h2_client.ml +++ b/lib_test/test_h2_client.ml @@ -1346,7 +1346,12 @@ module Client_connection_tests = struct frames) let test_fragmented_request_body_chunking () = - let t = create_and_handle_preface () in + let config = + { Config.default with + read_buffer_size = Settings.default.max_frame_size + } + in + let t = create_and_handle_preface ~config () in let request = Request.create ~scheme:"http" `POST "/" in let response_handler _response _response_body = () in let request_body = diff --git a/lib_test/test_h2_server.ml b/lib_test/test_h2_server.ml index fe2bc0a..af9f93f 100644 --- a/lib_test/test_h2_server.ml +++ b/lib_test/test_h2_server.ml @@ -940,6 +940,7 @@ module Server_connection_tests = struct = { Settings.default with enable_push = false ; max_concurrent_streams = 2l + ; max_frame_size = Config.default.read_buffer_size }); (match next_write_operation t with | `Write iovecs ->