Repository navigation
A response and a batch id are built without formatting machinery - #630
Merged
Merged
Conversation
Profiling the journal door put path ranked string formatting as 21% of its instructions, almost all of it producing strings that are a name, a separator and a value. write_response formatted every head line into a temporary String and copied it across: ten formatting calls per response, 7.65% of instructions per put. It now appends bytes and decimal digits directly through render_response. http_date wrote a fixed-width date through format!; it now writes the fields. replica_mutation_batch_id copied its prefix into a String and then formatted a second one, twice per replica per put; it now borrows the prefix and builds the id once. Every output is byte-identical, and each change keeps the original as an oracle in its test: the response head over 2,240 combinations of status, headers (including values that carry CR or LF), body size, keep-alive and HEAD; the date over a 20,000-value sweep and the four-digit year boundary; the batch id over 77 shapes including the 220-byte hashing limit. Measured with callgrind on the journal door at three replicas, 1,000 puts of 1 KiB: 158,203 -> 133,923 instructions per put (-15.3%). Formatting fell from 33.8M to 12.6M instructions in total. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
What the profile said
Callgrind of the journal door put path (three replicas, 1,000 puts of 1 KiB) ranked
format!as 21% of all instructions, 25 formatting calls per put, almost all of it building strings that are a name, a separator and a value:net::http::write_responsereplica_mutation_batch_idnet::http::http_dateThe change
write_responsenow renders throughrender_response, appending bytes and decimal digits directly.http_datewrites its fields directly instead of oneformat!with seven arguments.replica_mutation_batch_idborrows the prefix and builds the id once; it used to copy the prefix into aStringand format a second one, twice per replica per put (begin and end).No stored bytes or protocol bytes change.
Measured
Callgrind, journal door, three replicas, 1,000 puts of 1 KiB, instructions per put:
format_inner, all callerswrite_responsereplica_mutation_batch_idWhy the output is identical
Each of the three changes keeps the original implementation in its test as an oracle and compares byte for byte:
a_rendered_response_is_byte_for_byte_the_formatted_one: 2,240 combinations of 14 statuses (including ones that forbid a body and one with no reason phrase), four header sets (including values containing CR or LF, which are dropped), five body sizes up to 70,000 bytes, keep-alive and HEAD.an_http_date_is_the_formatted_one_over_a_wide_sweep: 20,000 pseudo-random epochs through 2200 plus the leap days, the 4-digit-year boundary (253402300799999and the next two values), andu64::MAX.a_replica_batch_id_is_the_formatted_one_for_every_shape_of_page_batch_id: 77 shapes: empty, short, unicode, exactly 220 bytes (not hashed), 221 (hashed), 1,000, and replica indexes throughusize::MAX.decimal_digits_are_printed_as_the_formatter_prints_themfor the digit writer.Full lib suite: 685 pass. The one failure,
the_published_mutation_copy_figures_are_the_ones_this_tree_produces(README 2485 vs tree 2557), fails identically on unmodifiedmainand is untouched here.🤖 Generated with Claude Code