<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alex Georgiev</title>
    <description>The latest articles on DEV Community by Alex Georgiev (@alexgeorgiev17).</description>
    <link>https://dev.to/alexgeorgiev17</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F374570%2Ffd187417-a674-43c9-951a-81c6fb965471.png</url>
      <title>DEV Community: Alex Georgiev</title>
      <link>https://dev.to/alexgeorgiev17</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alexgeorgiev17"/>
    <language>en</language>
    <item>
      <title>PostgreSQL 19's pg_plan_advice turned a 28ms query into 264ms under load</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Mon, 16 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/postgresql-19s-pgplanadvice-turned-a-28ms-query-into-264ms-under-load-46o5</link>
      <guid>https://dev.to/alexgeorgiev17/postgresql-19s-pgplanadvice-turned-a-28ms-query-into-264ms-under-load-46o5</guid>
      <description>&lt;p&gt;A ten-client pgbench run against a plain indexed lookup averaged 28ms a query. The same run, with one &lt;code&gt;SET&lt;/code&gt; command telling PostgreSQL to use a sequential scan instead of the index it already wanted, averaged 264ms. Nothing else changed: same table, same data, same hardware, same query.&lt;/p&gt;

&lt;p&gt;That &lt;code&gt;SET&lt;/code&gt; command is PostgreSQL 19's new &lt;code&gt;pg_plan_advice&lt;/code&gt;, a contrib module that lets you hand the planner a hint string and watch it comply, or tell you exactly why it didn't. PostgreSQL 19 is still at RC2 as I write this, pulled from Docker Hub as &lt;code&gt;postgres:19rc2&lt;/code&gt; on 14 November. It isn't GA yet, so anything here could still shift before release.&lt;/p&gt;

&lt;p&gt;I went looking for a case where the hint would help. I didn't find one. What I found instead was a precise, well-documented way to make a healthy query slow, and a feedback system that is more honest about its own limits than most planner-hint tools I've used in other databases.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;I built two tables: 50,000 customers and 2,000,000 orders, with &lt;code&gt;status&lt;/code&gt; skewed so that 0.5% of orders are &lt;code&gt;'refunded'&lt;/code&gt; and the rest are &lt;code&gt;'shipped'&lt;/code&gt;. An index on &lt;code&gt;status&lt;/code&gt; makes the refunded lookup cheap. This is the kind of table every production database has one of.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_orders_status&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;ANALYZE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;EXPLAIN&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ANALYZE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;COSTS&lt;/span&gt; &lt;span class="no"&gt;OFF&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;TIMING&lt;/span&gt; &lt;span class="no"&gt;OFF&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="cm"&gt;(*), sum(o.amount)
FROM orders o JOIN customers c ON o.customer_id = c.id
WHERE o.status = 'refunded'
GROUP BY c.region;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The planner picked an index scan on &lt;code&gt;orders&lt;/code&gt; feeding a hash join against a sequential scan of the small &lt;code&gt;customers&lt;/code&gt; table. Three repeated runs: 24.8ms (cold), 16.5ms, 18.0ms. That's the baseline for everything below.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pg_plan_advice&lt;/code&gt; works in two halves. &lt;code&gt;EXPLAIN (PLAN_ADVICE)&lt;/code&gt; tells you the advice string that would reproduce the plan you just got:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Generated Plan Advice:
   JOIN_ORDER(o c)
   HASH_JOIN(c)
   SEQ_SCAN(c)
   INDEX_SCAN(o public.idx_orders_status)
   NO_GATHER(o c)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And &lt;code&gt;SET pg_plan_advice.advice = '...'&lt;/code&gt; feeds a string back in, which the planner then tries to honour, with feedback on how well it managed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Forcing the wrong plan
&lt;/h2&gt;

&lt;p&gt;I took the advice vocabulary (&lt;code&gt;SEQ_SCAN&lt;/code&gt;, &lt;code&gt;INDEX_SCAN&lt;/code&gt;, &lt;code&gt;HASH_JOIN&lt;/code&gt;, &lt;code&gt;NESTED_LOOP_PLAIN&lt;/code&gt;, and a dozen others for merge joins, partitionwise plans, and parallel workers) and used it to force the one plan the planner had already rejected: a sequential scan on &lt;code&gt;orders&lt;/code&gt; instead of the index scan.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setup&lt;/th&gt;
&lt;th&gt;Single run&lt;/th&gt;
&lt;th&gt;Median of 3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Planner's own choice (index scan + hash join)&lt;/td&gt;
&lt;td&gt;16.5 / 18.0 / 24.8 ms&lt;/td&gt;
&lt;td&gt;18.0 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Forced &lt;code&gt;SEQ_SCAN(o)&lt;/code&gt;, join left alone&lt;/td&gt;
&lt;td&gt;46.1 / 51.7 / 43.6 ms&lt;/td&gt;
&lt;td&gt;46.1 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Forced &lt;code&gt;SEQ_SCAN(o)&lt;/code&gt; + &lt;code&gt;NESTED_LOOP_PLAIN(o c)&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;48.9 / 52.9 / 41.3 ms&lt;/td&gt;
&lt;td&gt;48.9 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Forcing just the scan method cost roughly as much as forcing the scan method and the join method together. The scan choice was doing almost all the work; the join strategy barely mattered once the input was a full table instead of 10,000 rows out of an index.&lt;/p&gt;

&lt;p&gt;Under concurrency the gap widened a lot further. I ran both plans through &lt;code&gt;pgbench&lt;/code&gt; with 10 clients for 10 seconds:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Plan&lt;/th&gt;
&lt;th&gt;Transactions&lt;/th&gt;
&lt;th&gt;Avg latency&lt;/th&gt;
&lt;th&gt;tps&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Planner's own choice&lt;/td&gt;
&lt;td&gt;3,519&lt;/td&gt;
&lt;td&gt;28.5 ms&lt;/td&gt;
&lt;td&gt;351.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Forced &lt;code&gt;SEQ_SCAN(o)&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;384&lt;/td&gt;
&lt;td&gt;264.0 ms&lt;/td&gt;
&lt;td&gt;37.9&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A 2.6x penalty on one connection became a 9.3x penalty on ten. Ten sequential scans over a 2-million-row table compete for the same buffer pages and CPU far harder than ten index probes do; the single-client number understates what a bad hint costs you in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  The opposite reading: I never found a case where it helped
&lt;/h2&gt;

&lt;p&gt;This is the part that mattered most to me. I expected to spend most of my time hunting for a query where PostgreSQL's planner gets it wrong and the hint fixes it. I built a schema where &lt;code&gt;region&lt;/code&gt; and &lt;code&gt;tier&lt;/code&gt; are perfectly correlated (both derived from the same &lt;code&gt;id % 3&lt;/code&gt;), which should make the planner underestimate a combined filter on both columns under the independence assumption it still uses for most predicates.&lt;/p&gt;

&lt;p&gt;It did underestimate: a filter I knew matched 16,666 rows was costed as if it would match roughly a third of that. But the plan it picked anyway — a hash join — stayed the fastest option regardless, because the table was small enough that the misestimate never changed which plan was cheapest. I could not get PostgreSQL 19 RC2 to pick a genuinely bad default plan on this schema no matter how I skewed the correlation. Every advice string I supplied either matched what the planner already intended, or made things worse.&lt;/p&gt;

&lt;p&gt;That matches what I'd read going in: this is advice for pinning a plan you already trust, under a connection pooler or a parameter that occasionally throws the planner off, not a tool for correcting bad row estimates on the fly. I just hadn't believed it until I'd tried to break it for an hour and failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses
&lt;/h2&gt;

&lt;p&gt;Three cases, with the exact feedback PostgreSQL gives:&lt;/p&gt;

&lt;p&gt;A nonexistent index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Supplied Plan Advice:
  INDEX_SCAN(o no_such_index) /* matched, inapplicable, failed */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Contradictory advice on the same table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Supplied Plan Advice:
  SEQ_SCAN(o) /* matched, conflicting, failed */
  INDEX_SCAN(o idx_orders_status) /* matched, conflicting, failed */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both of these are refused safely — the query ran on the planner's own chosen plan, not a broken one. The one that worried me was a misspelled or missing table alias:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Supplied Plan Advice:
  SEQ_SCAN(zzz) /* not matched */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No error. No warning. The query just ran as if you'd supplied no advice at all, which is exactly what you'd want if you're testing, and exactly what you don't want if you've just typo'd an alias in a connection pooler's startup script and are now silently not getting the plan you think you configured.&lt;/p&gt;

&lt;p&gt;There is a documented fix: &lt;code&gt;pg_plan_advice.feedback_warnings&lt;/code&gt;. With it on, the same typo produces a real log line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WARNING:  supplied plan advice was not enforced
DETAIL:  advice SEQ_SCAN(zzz) feedback is "not matched"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I turned it on and it did exactly what the documentation says. It's off by default, which means the failure mode most likely to bite someone — advice silently doing nothing — is also the one you have to opt into being told about.&lt;/p&gt;

&lt;h2&gt;
  
  
  The documented caveat, and one it doesn't mention
&lt;/h2&gt;

&lt;p&gt;The docs warn that a cached prepared-statement plan won't notice a new &lt;code&gt;pg_plan_advice.advice&lt;/code&gt; value until you run &lt;code&gt;DISCARD PLANS&lt;/code&gt;. I reproduced this exactly. I forced &lt;code&gt;plan_cache_mode = force_generic_plan&lt;/code&gt; so the first &lt;code&gt;EXECUTE&lt;/code&gt; would cache a plan, set the advice to request a sequential scan, executed once (got the seq scan, as asked), then changed the advice to request the index scan and executed again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- exec 2, advice changed to INDEX_SCAN, plan still cached from before
Finalize Aggregate
  -&amp;gt;  Gather
        -&amp;gt;  Partial Aggregate
              -&amp;gt;  Parallel Seq Scan on orders
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Still the seq scan. Only after &lt;code&gt;DISCARD PLANS&lt;/code&gt; did the next execution switch to the index scan. What the docs don't mention: &lt;code&gt;EXPLAIN (PLAN_ADVICE)&lt;/code&gt; against that stale cached execution showed no &lt;code&gt;Supplied Plan Advice&lt;/code&gt; section at all, because no replanning happened. If you're checking whether your new advice took effect by looking for that section, its absence looks identical to "nothing was supplied," not "your advice was ignored." I'd have assumed I'd made a typo before I'd have suspected caching.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs when idle
&lt;/h2&gt;

&lt;p&gt;With the module loaded fresh via &lt;code&gt;LOAD&lt;/code&gt; on every transaction, a trivial single-row count ran at 0.457ms average latency against 0.408ms with the module absent entirely — a real but small 12% tax, and it's the tax of calling &lt;code&gt;LOAD&lt;/code&gt; every time, not the module's planning hook. Preloaded once via &lt;code&gt;shared_preload_libraries&lt;/code&gt;, the same query ran at 0.377ms, indistinguishable from not having the module at all. If you're going to use this in production, preload it; don't &lt;code&gt;LOAD&lt;/code&gt; it per connection.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;I spent close to half my testing time chasing a theory that turned out false: that a prepared statement with a parameter on the skewed &lt;code&gt;status&lt;/code&gt; column would flip to a bad generic plan after Postgres's usual five-execution custom-plan threshold, because I assumed the generic plan would use a naive uniform-selectivity estimate for an unbound parameter. It didn't. PostgreSQL's planner already uses the column's most-common-value statistics when building the generic plan, so it picked the index scan on execution six exactly as it had on execution one — 9.99ms down to 3.3ms, with no flip at all. The "advice fixes a plan regression" post I'd half-planned to write wasn't there. The honest finding was that the planner didn't need fixing, and the correlated-columns schema in the section above was my second attempt at the same thing, which also failed to produce a bad default plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;

&lt;p&gt;This needs Docker and about ten minutes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run -d --name pg19 -e &lt;span class="nv"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt; postgres:19rc2
sleep 6

cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; runit.sql &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'SQL'&lt;/span&gt;
CREATE TABLE customers &lt;span class="o"&gt;(&lt;/span&gt;id bigint PRIMARY KEY, region text, tier text&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
CREATE TABLE orders &lt;span class="o"&gt;(&lt;/span&gt;id bigint PRIMARY KEY, customer_id bigint REFERENCES customers&lt;span class="o"&gt;(&lt;/span&gt;id&lt;span class="o"&gt;)&lt;/span&gt;,
                      status text NOT NULL, amount numeric NOT NULL&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
INSERT INTO customers SELECT g, &lt;span class="o"&gt;(&lt;/span&gt;ARRAY&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'eu'&lt;/span&gt;,&lt;span class="s1"&gt;'us'&lt;/span&gt;,&lt;span class="s1"&gt;'apac'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;1+g%3&lt;span class="o"&gt;]&lt;/span&gt;, &lt;span class="o"&gt;(&lt;/span&gt;ARRAY&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'gold'&lt;/span&gt;,&lt;span class="s1"&gt;'silver'&lt;/span&gt;,&lt;span class="s1"&gt;'bronze'&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;1+g%3&lt;span class="o"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; generate_series&lt;span class="o"&gt;(&lt;/span&gt;1,50000&lt;span class="o"&gt;)&lt;/span&gt; g&lt;span class="o"&gt;;&lt;/span&gt;
INSERT INTO orders SELECT g, 1+&lt;span class="o"&gt;(&lt;/span&gt;g%50000&lt;span class="o"&gt;)&lt;/span&gt;,
  CASE WHEN g % 200 &lt;span class="o"&gt;=&lt;/span&gt; 0 THEN &lt;span class="s1"&gt;'refunded'&lt;/span&gt; ELSE &lt;span class="s1"&gt;'shipped'&lt;/span&gt; END, &lt;span class="o"&gt;(&lt;/span&gt;random&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;*500&lt;span class="o"&gt;)&lt;/span&gt;::numeric&lt;span class="o"&gt;(&lt;/span&gt;10,2&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; generate_series&lt;span class="o"&gt;(&lt;/span&gt;1,2000000&lt;span class="o"&gt;)&lt;/span&gt; g&lt;span class="o"&gt;;&lt;/span&gt;
CREATE INDEX idx_orders_status ON orders &lt;span class="o"&gt;(&lt;/span&gt;status&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
ANALYZE&lt;span class="o"&gt;;&lt;/span&gt;

LOAD &lt;span class="s1"&gt;'pg_plan_advice'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

-- the planner&lt;span class="s1"&gt;'s own choice
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)
SELECT c.region, count(*), sum(o.amount) FROM orders o JOIN customers c
  ON o.customer_id = c.id WHERE o.status = '&lt;/span&gt;refunded&lt;span class="s1"&gt;' GROUP BY c.region;

-- force a sequential scan instead
SET pg_plan_advice.advice = '&lt;/span&gt;SEQ_SCAN&lt;span class="o"&gt;(&lt;/span&gt;o&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="s1"&gt;';
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, PLAN_ADVICE)
SELECT c.region, count(*), sum(o.amount) FROM orders o JOIN customers c
  ON o.customer_id = c.id WHERE o.status = '&lt;/span&gt;refunded&lt;span class="s1"&gt;' GROUP BY c.region;
SQL

docker cp runit.sql pg19:/tmp/runit.sql
docker exec pg19 psql -U postgres -f /tmp/runit.sql
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the concurrency numbers, swap the last &lt;code&gt;EXPLAIN&lt;/code&gt; block for a &lt;code&gt;pgbench&lt;/code&gt; custom script with the same &lt;code&gt;SET&lt;/code&gt; line in it and run &lt;code&gt;pgbench -U postgres -n -c 10 -T 10 -f script.sql postgres&lt;/code&gt; against both the advised and un-advised versions.&lt;/p&gt;

&lt;p&gt;Run your own forced-scan test through pgbench with at least ten clients before you pin a plan anywhere permanent, such as a pooler's startup script or postgresql.conf. My single-connection number was 2.6x. My ten-client number was 9.3x. Production traffic looks like the second number, not the first, and I almost stopped testing before I found that out.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>database</category>
      <category>performance</category>
      <category>devops</category>
    </item>
    <item>
      <title>uv 0.13's tar-codec backend installs a 6,000-file sdist in 2.5 seconds instead of 3.8</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Sun, 15 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/uv-013s-tar-codec-backend-installs-a-6000-file-sdist-in-25-seconds-instead-of-38-2ijc</link>
      <guid>https://dev.to/alexgeorgiev17/uv-013s-tar-codec-backend-installs-a-6000-file-sdist-in-25-seconds-instead-of-38-2ijc</guid>
      <description>&lt;p&gt;I built a source distribution with 6,000 small files in it and installed it with &lt;code&gt;uv pip install&lt;/code&gt;. With uv 0.13.6, the median time across five runs was 2.53 seconds. With the same binary told to use the old extraction code, the median was 3.55 seconds. With the actual pre-change release, 0.12.8, it was 3.76 seconds.&lt;/p&gt;

&lt;p&gt;That's the headline, and it's a real number from a real install, not a microbenchmark of tar extraction in isolation. The part I didn't expect going in was what happened when I fed the new backend a source distribution with a character device node baked into it. The old backend installed it anyway and silently threw the device file away. The new one refuses the whole install and tells you exactly why.&lt;/p&gt;

&lt;p&gt;uv is Astral's Rust-based replacement for pip, venv and friends. Version 0.13.0, released on 9 October 2026, swapped the library it uses to extract &lt;code&gt;.tar.gz&lt;/code&gt; archives from &lt;code&gt;astral-tokio-tar&lt;/code&gt; to a newer one called &lt;code&gt;tar-codec&lt;/code&gt;. The release notes say the new backend "applies stricter validation when reading archives" and warns that archives with hard links or unsupported tar extensions that older versions accepted may now be rejected. There's an escape hatch: setting &lt;code&gt;UV_LEGACY_TAR_BACKEND=1&lt;/code&gt; restores the old code path. That one environment variable made this easy to test properly, because I could hold the binary constant and flip only the backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  The install-time number
&lt;/h2&gt;

&lt;p&gt;I generated a package called &lt;code&gt;bigpkg&lt;/code&gt; with 6,000 text files totalling 48MB uncompressed (36MB as a gzipped tarball), gave it a trivial &lt;code&gt;pyproject.toml&lt;/code&gt; using the setuptools backend, and installed it with &lt;code&gt;--no-deps&lt;/code&gt; into a fresh virtual environment each time, with a fresh cache directory each time. Five runs per configuration:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Configuration&lt;/th&gt;
&lt;th&gt;Run times (s)&lt;/th&gt;
&lt;th&gt;Median&lt;/th&gt;
&lt;th&gt;Fastest&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;uv 0.13.6, default (tar-codec)&lt;/td&gt;
&lt;td&gt;2.50, 2.52, 2.53, 2.61, 2.75&lt;/td&gt;
&lt;td&gt;2.53s&lt;/td&gt;
&lt;td&gt;2.50s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;uv 0.13.6, &lt;code&gt;UV_LEGACY_TAR_BACKEND=1&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;3.07, 3.46, 3.55, 3.76, 4.84&lt;/td&gt;
&lt;td&gt;3.55s&lt;/td&gt;
&lt;td&gt;3.07s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;uv 0.12.8 (pre-change release)&lt;/td&gt;
&lt;td&gt;3.21, 3.42, 3.76, 3.93, 5.12&lt;/td&gt;
&lt;td&gt;3.76s&lt;/td&gt;
&lt;td&gt;3.21s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That's a 29% drop in median time against the same binary with the old flag set, and 33% against the actual old release. The fastest-run comparison is less dramatic — 2.50s against 3.07s and 3.21s, around 18-22% — because the slowest outliers in the legacy runs inflate the median more than the minimum. Either way the direction is consistent across all fifteen runs: tar-codec never lost to the legacy path on this workload.&lt;/p&gt;

&lt;p&gt;I deliberately used a package with many small files rather than one large file, because that's where tar's per-entry overhead shows up. When I first tried this with a package containing 400 files and 8MB of data, the three configurations landed within noise of each other — 0.96 to 2.6 seconds with no clear ordering. The fixed cost of spinning up a Python subprocess to run the setuptools build backend was swamping the extraction time. Scaling up to 6,000 files is what made the effect visible. If you're testing this yourself and see "no difference," that's very likely your workload being too small, not the feature being inert.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses, and what it used to do silently
&lt;/h2&gt;

&lt;p&gt;The release notes mention hard links and "unsupported tar extensions." I built four adversarial archives with Python's &lt;code&gt;tarfile&lt;/code&gt; module: one with a hard link pointing at &lt;code&gt;../../../../../../etc/passwd&lt;/code&gt;, one with an absolute symlink to &lt;code&gt;/etc/passwd&lt;/code&gt;, one with a GNU sparse-file entry missing its required header, and one with a character device node.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Archive&lt;/th&gt;
&lt;th&gt;uv 0.13.6 default&lt;/th&gt;
&lt;th&gt;uv 0.13.6 legacy flag&lt;/th&gt;
&lt;th&gt;uv 0.12.8&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hard link escaping the extraction root&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Absolute symlink&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Malformed sparse entry&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Character device node&lt;/td&gt;
&lt;td&gt;rejected&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;installed&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;installed&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three of the four are a wash. This is the finding that argues against my own headline: the path-escape protections for hard links and symlinks aren't new in 0.13. The old backend already refused them, with almost the same wording:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# uv 0.12.8 (old backend)
error: Failed to extract archive: file:///.../malicious/evil_hardlink.tar.gz
  Caused by: Invalid tar file
  Caused by: failed to unpack `.../evilpkg-0.0.1/evilpkg/escape_hardlink`
  Caused by: trying to unpack outside of destination path: ...
  Caused by: Invalid argument
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# uv 0.13.6 (new backend, default)
error: Failed to extract archive: file:///.../malicious/evil_hardlink.tar.gz
  cause: Invalid tar file
  cause: at byte 2560: unsafe hard-link target "../../../../../../etc/passwd": escapes the destination root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same outcome, better message — the new one names the exact byte offset and says plainly what's wrong, instead of surfacing a bare OS-level "Invalid argument." But if you were hoping 0.13 closed a hard-link escape that 0.12 left open, it didn't need to: that door was already shut.&lt;/p&gt;

&lt;p&gt;The real difference is the character device. Here's the full output of installing a package that embeds one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ uv pip install evil_chardev.tar.gz --no-deps
error: Failed to extract archive: file:///.../malicious/evil_chardev.tar.gz
  cause: Invalid tar file
  cause: at byte 2560: cannot extract unsupported member type CharacterDevice at evilpkg-0.0.1/evilpkg/weird_device
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the legacy flag, or with 0.12.8, the same archive installs cleanly: "Resolved 1 package", "Installed 1 package", no warning anywhere. I checked the resulting &lt;code&gt;site-packages&lt;/code&gt; directory for the device node and it isn't there either — the old backend didn't create it, it just dropped the tar entry on the floor without telling anyone. The install reports success either way. That's the actual behaviour change: not new rejections of things that were dangerous, but a loud failure in place of a silent, undocumented truncation of package contents. For a package that legitimately shouldn't contain device nodes, fine. For a package that had something unusual in it for a reason, the new behaviour at least tells you your install isn't what you think it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;I wanted to check a boring, legitimate use of hard links too — a package shipping the same file twice via a hard link instead of duplicating it, which is a normal thing for sdists to do. I built one and installed it with all three configurations. All three succeeded with no extraction errors, which looked like confirmation that ordinary hard links are unaffected.&lt;/p&gt;

&lt;p&gt;Then I went looking for the actual file in the installed package and it wasn't there — neither the original nor the hard-linked copy. I'd forgotten that setuptools, without a &lt;code&gt;MANIFEST.in&lt;/code&gt; or explicit &lt;code&gt;package_data&lt;/code&gt;, only packages &lt;code&gt;.py&lt;/code&gt; files into the wheel it builds from an sdist. My &lt;code&gt;.txt&lt;/code&gt; data files were silently excluded by the build backend, nothing to do with the tar extraction step at all. The extraction succeeded; the wheel build just never looked at those files. I had to go back and read the DEBUG-level build log to confirm the hard link itself caused no extraction error, which it didn't — it's a genuine non-finding, but I almost reported it as "hard links work fine" based on output that was actually testing setuptools' packaging defaults.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an upgrade costs you once
&lt;/h2&gt;

&lt;p&gt;The 0.13.0 changelog says the cache entry format changed, so uv "may download or rebuild dependencies after upgrading." I populated a cache directory with 0.12.8, then pointed 0.13.6 at the same directory and installed the identical archive again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DEBUG Identified uncached distribution: bigpkg @ file:///.../bigpkg-0.0.1.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Despite the exact same tarball already having been built into that cache directory seconds earlier, the new version treated it as uncached and rebuilt it. The cache directory grew from 52MB to 104MB rather than staying flat. That's a one-time cost on the first run after upgrading, not a recurring one, but it's worth knowing before you time a CI pipeline right after bumping the uv version — your first post-upgrade run won't reflect your steady-state numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two smaller checks
&lt;/h2&gt;

&lt;p&gt;uv 0.13 also stabilised a change where it stops writing &lt;code&gt;_virtualenv.py&lt;/code&gt; and &lt;code&gt;_virtualenv.pth&lt;/code&gt; into new virtual environments on Python 3.10 and newer, matching what &lt;code&gt;virtualenv&lt;/code&gt; itself does from 21.6.0. I confirmed it directly: &lt;code&gt;uv venv&lt;/code&gt; with 0.12.8 on Python 3.11 produces 15 files in the environment, including those two; 0.13.6 produces 13. Two fewer files, every time, on every new environment.&lt;/p&gt;

&lt;p&gt;I also ran eight &lt;code&gt;uv pip install&lt;/code&gt; processes against the same big archive concurrently, sharing one cache directory, to see whether the new extraction path handles contention any worse than the old one. All eight finished successfully with no lock errors or corrupted installs, in 25 seconds total wall time. I didn't find anything interesting here — it held up — so I'm reporting that in one line rather than dressing it up as a finding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;

&lt;p&gt;This is the core of the timing test, trimmed to the essentials. It needs &lt;code&gt;uv&lt;/code&gt; 0.13.x and 0.12.x installed into separate locations (I used &lt;code&gt;pip install "uv==0.13.6"&lt;/code&gt; and &lt;code&gt;pip install "uv==0.12.8"&lt;/code&gt; into two throwaway virtualenvs) and a synthetic sdist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# build a 6,000-file sdist called bigpkg-0.0.1.tar.gz first, then:&lt;/span&gt;

run_install&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;uvbin&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;extra_env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$3&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; i &lt;span class="k"&gt;in&lt;/span&gt; 1 2 3 4 5&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="nv"&gt;cachedir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;mktemp -d&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;venvdir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;mktemp -d&lt;span class="o"&gt;)&lt;/span&gt;
    python3 -I -m venv &lt;span class="s2"&gt;"$venvdir/venv"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1
    &lt;span class="nv"&gt;t0&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date +%s.%N&lt;span class="o"&gt;)&lt;/span&gt;
    env &lt;span class="nv"&gt;$extra_env&lt;/span&gt; &lt;span class="nv"&gt;UV_CACHE_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$cachedir"&lt;/span&gt; &lt;span class="s2"&gt;"$uvbin"&lt;/span&gt; pip install \
      --python &lt;span class="s2"&gt;"$venvdir/venv/bin/python"&lt;/span&gt; ./bigpkg-0.0.1.tar.gz --no-deps -q
    &lt;span class="nv"&gt;t1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date +%s.%N&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$label run $i: $(echo "&lt;/span&gt;&lt;span class="nv"&gt;$t1&lt;/span&gt; - &lt;span class="nv"&gt;$t0&lt;/span&gt;&lt;span class="s2"&gt;" | bc)s"&lt;/span&gt;
    rm -rf &lt;span class="s2"&gt;"$cachedir"&lt;/span&gt; &lt;span class="s2"&gt;"$venvdir"&lt;/span&gt;
  &lt;span class="k"&gt;done&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

run_install &lt;span class="s2"&gt;"new_default"&lt;/span&gt; ./venv_new/bin/uv &lt;span class="s2"&gt;""&lt;/span&gt;
run_install &lt;span class="s2"&gt;"new_legacy"&lt;/span&gt;  ./venv_new/bin/uv &lt;span class="s2"&gt;"UV_LEGACY_TAR_BACKEND=1"&lt;/span&gt;
run_install &lt;span class="s2"&gt;"old_uv"&lt;/span&gt;      ./venv_old/bin/uv &lt;span class="s2"&gt;""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the character-device check, build an archive with Python's &lt;code&gt;tarfile&lt;/code&gt; module, set a &lt;code&gt;TarInfo&lt;/code&gt;'s &lt;code&gt;type&lt;/code&gt; to &lt;code&gt;tarfile.CHRTYPE&lt;/code&gt;, and add it alongside a normal &lt;code&gt;pyproject.toml&lt;/code&gt; and &lt;code&gt;PKG-INFO&lt;/code&gt;. Installing it with and without &lt;code&gt;UV_LEGACY_TAR_BACKEND=1&lt;/code&gt; is enough to see both behaviours side by side.&lt;/p&gt;

&lt;p&gt;If you're installing sdists in CI — your own private packages, vendored dependencies, anything that isn't a prebuilt wheel — upgrading to 0.13 is a straightforward win on install time, with no downside I found for ordinary archives. The one thing worth checking first is whether anything in your build pipeline relies on tar entries that aren't plain files, symlinks or regular hard links; those are now a hard failure instead of a silent gap, which is very likely what you want, but it will surface as a new error on the next build rather than a difference you'd notice by reading a diff.&lt;/p&gt;

</description>
      <category>python</category>
      <category>performance</category>
      <category>devops</category>
      <category>security</category>
    </item>
    <item>
      <title>nginx 1.31's json_set directive rejects a bad webhook payload about 13 times faster than forwarding it</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Sat, 14 Nov 2026 12:48:45 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/nginx-131s-jsonset-directive-rejects-a-bad-webhook-payload-about-13-times-faster-than-forwarding-3b00</link>
      <guid>https://dev.to/alexgeorgiev17/nginx-131s-jsonset-directive-rejects-a-bad-webhook-payload-about-13-times-faster-than-forwarding-3b00</guid>
      <description>&lt;p&gt;A webhook receiver I built a few years ago always worked the same way: nginx took the connection, nginx forwarded the body, and the application decided whether the payload was junk. nginx 1.31.5 adds a module that lets nginx make that decision itself, by reading fields out of the JSON body before the request ever reaches a location block. I wanted to know what that was actually worth, not just what the changelog implied.&lt;/p&gt;

&lt;p&gt;The module is &lt;code&gt;ngx_http_json_module&lt;/code&gt;, built with &lt;code&gt;--with-http_json_module&lt;/code&gt; (it's compiled into the official Docker image, but not into Ubuntu's 24.04 &lt;code&gt;nginx&lt;/code&gt; apt package, which still ships 1.24.0). It adds one directive that matters, &lt;code&gt;json_set&lt;/code&gt;, plus a depth limit. Alongside it, 1.31.5 also shipped predicate locations (&lt;code&gt;location $variable&lt;/code&gt;) and &lt;code&gt;client_body_early_read&lt;/code&gt;, which together let a location match be decided by the request body instead of only the URI.&lt;/p&gt;

&lt;p&gt;I pulled &lt;code&gt;nginx:1.31.8&lt;/code&gt; (the current mainline patch, released 21 October 2026) and built the smallest realistic case: a webhook endpoint that only wants two event types, &lt;code&gt;payment.created&lt;/code&gt; and &lt;code&gt;payment.failed&lt;/code&gt;, and should reject everything else without bothering the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;Old way, everything proxied through:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;18090&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;proxy_http_version&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//backend;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;New way, rejecting at the edge:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;client_body_early_read&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;json_set&lt;/span&gt; $&lt;span class="n"&gt;event_type&lt;/span&gt; $&lt;span class="n"&gt;request_body&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;map&lt;/span&gt; $&lt;span class="n"&gt;event_type&lt;/span&gt; $&lt;span class="n"&gt;is_invalid_event&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"payment.created"&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="s2"&gt;"payment.failed"&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;           &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;18091&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;location&lt;/span&gt; $&lt;span class="n"&gt;is_invalid_event&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt; &lt;span class="s2"&gt;"unknown event type\n"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;proxy_http_version&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="nc"&gt;Connection&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//backend;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The backend is a small threaded Python server that parses the same JSON and returns 400 for anything that isn't one of the two valid event types, so both paths enforce the identical rule. I ran everything on loopback, no Docker network between containers, &lt;code&gt;--network host&lt;/code&gt; so there's no extra hop to argue about.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it actually saved
&lt;/h2&gt;

&lt;p&gt;I sent 200 requests, alternating valid and invalid payloads, through each config and counted how many reached the backend:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;requests sent&lt;/th&gt;
&lt;th&gt;reached backend&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;old way (run 1/2/3)&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;200 / 200 / 200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;new way (run 1/2/3)&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;100 / 100 / 100&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every single invalid request was turned away at nginx. The backend never saw it. That's the entire point of the feature in one table: it's not about nginx being faster at HTTP, it's about deciding which requests are worth a backend's time before spending any.&lt;/p&gt;

&lt;h2&gt;
  
  
  The headline number
&lt;/h2&gt;

&lt;p&gt;At concurrency 1, no contention, I measured the time to reject (or round-trip and reject) 1,000 invalid payloads, three times each:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;run&lt;/th&gt;
&lt;th&gt;old way (round trip)&lt;/th&gt;
&lt;th&gt;new way (rejected at nginx)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1,840 req/s&lt;/td&gt;
&lt;td&gt;25,780 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2,006 req/s&lt;/td&gt;
&lt;td&gt;21,862 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;1,775 req/s&lt;/td&gt;
&lt;td&gt;25,153 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Averaged, that's about 1,874 req/s against 24,265 req/s — roughly 13 times faster to say no. That gap is real and it isn't contention-related, since there's only one request in flight at a time either way. It's the cost of a TCP round trip and a Python thread versus a variable lookup.&lt;/p&gt;

&lt;h2&gt;
  
  
  The opposite reading
&lt;/h2&gt;

&lt;p&gt;The obvious question is what this costs you when there's nothing to reject. I ran 3,000 all-valid requests through both configs, serially, three times:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;run&lt;/th&gt;
&lt;th&gt;old way&lt;/th&gt;
&lt;th&gt;new way&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1,729 req/s&lt;/td&gt;
&lt;td&gt;1,680 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1,578 req/s&lt;/td&gt;
&lt;td&gt;1,688 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;1,572 req/s&lt;/td&gt;
&lt;td&gt;1,574 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That's noise, not a trend. I expected &lt;code&gt;json_set&lt;/code&gt; plus the extra &lt;code&gt;map&lt;/code&gt; lookup to cost something on every request even when nothing gets rejected, and I couldn't find it. At a 5% invalid mix the new way was consistently about 11-13% faster even though 95% of requests still had to go all the way to the backend either way, which argues the parsing cost is genuinely small relative to a real round trip.&lt;/p&gt;

&lt;h2&gt;
  
  
  Under concurrency, the comparison stops being fair
&lt;/h2&gt;

&lt;p&gt;At 10 concurrent clients sending nothing but junk, old way managed 1,433 req/s; new way did 86,046. At 100 concurrent clients, old way dropped to 49 req/s with 3 failed requests, while new way stayed above 109,000 with none. I'm not reporting that ratio as nginx being thousands of times faster than a backend in general — it's what happens when a single-process, thread-per-connection Python server gets saturated by a flood of requests it has to accept, parse and reject one at a time. Hit directly with no proxy in front, that same backend topped out around 2,500 req/s at concurrency 50. The real finding isn't the multiplier, it's that under load the backend's own capacity becomes the thing junk traffic eats into, and removing it from that path removes the exposure entirely rather than just making it faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the docs claim, checked
&lt;/h2&gt;

&lt;p&gt;The module docs say a JSON document "is parsed only once per request, on the first access to any variable extracted from it, no matter how many variables are extracted." I tested that by extracting one field against extracting five fields from the same request body, 5,000 requests at concurrency 1, three runs each:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;run&lt;/th&gt;
&lt;th&gt;1 field&lt;/th&gt;
&lt;th&gt;5 fields&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;26,202 req/s&lt;/td&gt;
&lt;td&gt;26,089 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;25,874 req/s&lt;/td&gt;
&lt;td&gt;24,203 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;26,080 req/s&lt;/td&gt;
&lt;td&gt;26,180 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Within 2% either way. The claim holds: whatever &lt;code&gt;json_set&lt;/code&gt; does internally, it isn't re-walking the document for every variable you pull out of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;json_max_depth&lt;/code&gt; defaults to 32. I sent a document nested 40 levels deep and asked for a value at the bottom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ curl -s -X POST http://127.0.0.1:18081/ --data-binary @deep40.json
&lt;span class="nv"&gt;deep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No error, no log line, nothing in &lt;code&gt;error_log&lt;/code&gt;. The variable is simply not found, exactly as if the field didn't exist or the JSON were malformed. If you're validating depth-sensitive payloads (deeply nested configuration blobs, arbitrary user-supplied trees), this will silently pass them through as "field missing" rather than flag them as "too deep," and your &lt;code&gt;map&lt;/code&gt; block needs to treat those two cases the same way whether you like it or not.&lt;/p&gt;

&lt;p&gt;Separately, &lt;code&gt;client_body_early_read&lt;/code&gt; is not the boolean it looks like. Its syntax is &lt;code&gt;client_body_early_read _string_ ...;&lt;/code&gt;, matched against one or more values, enabled if any is non-empty and isn't &lt;code&gt;"0"&lt;/code&gt;. Writing &lt;code&gt;client_body_early_read on;&lt;/code&gt; works, but only because the literal string &lt;code&gt;"on"&lt;/code&gt; happens to be non-empty and not &lt;code&gt;"0"&lt;/code&gt; — nginx isn't parsing it as a keyword. &lt;code&gt;client_body_early_read off;&lt;/code&gt; would also enable it, which is exactly backward from every other &lt;code&gt;*_module on/off&lt;/code&gt; directive in nginx and worth knowing before you copy a pattern from somewhere else in your config.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My first throughput run reported the new way at roughly 290 times faster than the old way at 50 concurrent clients, and I almost wrote that number down. It turned out to be a harness bug: &lt;code&gt;proxy_pass&lt;/code&gt; to the backend defaults to HTTP/1.0 with &lt;code&gt;Connection: close&lt;/code&gt;, so without an explicit &lt;code&gt;upstream { keepalive }&lt;/code&gt; block, nginx was opening a brand-new TCP connection per request to a backend on loopback, and at concurrency 50 that was exhausting ephemeral ports faster than they could leave &lt;code&gt;TIME_WAIT&lt;/code&gt;. The old way wasn't slow because it round-trips to a backend; it was slow because my config made every one of those round trips pay for a fresh handshake. Adding &lt;code&gt;keepalive 64&lt;/code&gt; to the upstream block and &lt;code&gt;proxy_http_version 1.1&lt;/code&gt; dropped the measured gap from 290x to a defensible 13x at low concurrency. The lesson wasn't about JSON parsing at all — it was that an unrealistic proxy config can make the "old way" look artificially bad, which would have flattered the feature I was trying to measure fairly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull nginx:1.31.8

cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; new_way.conf &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
worker_processes 1&lt;span class="o"&gt;;&lt;/span&gt;
events &lt;span class="o"&gt;{&lt;/span&gt; worker_connections 2048&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
http &lt;span class="o"&gt;{&lt;/span&gt;
    access_log off&lt;span class="o"&gt;;&lt;/span&gt;
    client_body_early_read 1&lt;span class="o"&gt;;&lt;/span&gt;
    upstream backend &lt;span class="o"&gt;{&lt;/span&gt; server 127.0.0.1:9001&lt;span class="o"&gt;;&lt;/span&gt; keepalive 64&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
    json_set &lt;span class="nv"&gt;$event_type&lt;/span&gt; &lt;span class="nv"&gt;$request_body&lt;/span&gt; event.type&lt;span class="o"&gt;;&lt;/span&gt;
    map &lt;span class="nv"&gt;$event_type&lt;/span&gt; &lt;span class="nv"&gt;$is_invalid_event&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"payment.created"&lt;/span&gt; 0&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="s2"&gt;"payment.failed"&lt;/span&gt;  0&lt;span class="o"&gt;;&lt;/span&gt;
        default           1&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    server &lt;span class="o"&gt;{&lt;/span&gt;
        listen 18091&lt;span class="o"&gt;;&lt;/span&gt;
        location &lt;span class="nv"&gt;$is_invalid_event&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;return&lt;/span&gt; 400 &lt;span class="s2"&gt;"unknown event type\n"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
        location / &lt;span class="o"&gt;{&lt;/span&gt;
            proxy_http_version 1.1&lt;span class="o"&gt;;&lt;/span&gt;
            proxy_set_header Connection &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            proxy_pass http://backend&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
EOF

docker run -d --name newway --network host \
  -v &lt;span class="s2"&gt;"$(pwd)/new_way.conf:/etc/nginx/nginx.conf:ro"&lt;/span&gt; nginx:1.31.8

curl -s -X POST http://127.0.0.1:18091/ -d &lt;span class="s1"&gt;'{"event":{"type":"payment.created"}}'&lt;/span&gt;
curl -s -i -X POST http://127.0.0.1:18091/ -d &lt;span class="s1"&gt;'{"event":{"type":"spam.click"}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without a listener on 9001 the valid-case curl just gets a 502, so point something at it first — any script that reads the body and answers 200 will do.&lt;/p&gt;

&lt;p&gt;Before you add this, run &lt;code&gt;nginx -V 2&amp;gt;&amp;amp;1 | grep json&lt;/code&gt; against whatever you've actually got running. The Ubuntu package doesn't have it. The official Docker image does. If yours does, pull yesterday's access log and count the 400s and 422s your app already wrote. That count is what tells you whether fifteen minutes of config is worth it, not the 13x I got against a toy backend.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>devops</category>
      <category>performance</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Git 2.56's history drop command replays commits 40 to 77 times faster than rebase</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Fri, 13 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/git-256s-history-drop-command-replays-commits-40-to-77-times-faster-than-rebase-45jm</link>
      <guid>https://dev.to/alexgeorgiev17/git-256s-history-drop-command-replays-commits-40-to-77-times-faster-than-rebase-45jm</guid>
      <description>&lt;p&gt;I wanted to remove one commit from the middle of a bare repository without checking anything out. The usual answer is: you can't, not directly. You add a worktree, rebase, then throw the worktree away. Git 2.56, released on 28 September 2026, ships an experimental command that skips all of that: &lt;code&gt;git history drop&lt;/code&gt;. I built it from source and measured what it actually saves.&lt;/p&gt;

&lt;p&gt;Short version: on a bare repo with 400 commits stacked after the one I wanted gone, the classic worktree-and-rebase approach took 26.5 seconds. &lt;code&gt;git history drop&lt;/code&gt; took 0.36 seconds. That's not a rounding difference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting it up
&lt;/h2&gt;

&lt;p&gt;Git 2.56.0 isn't in Ubuntu's apt repositories yet, and I don't have a release binary for it, so I built it from the tagged source:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git clone --depth 1 --branch v2.56.0 https://github.com/git/git.git git-src
$ &lt;span class="nb"&gt;cd&lt;/span&gt; git-src
$ make -j4 &lt;span class="nv"&gt;NO_GETTEXT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YesPlease &lt;span class="nv"&gt;NO_TCLTK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YesPlease &lt;span class="nv"&gt;NO_PERL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YesPlease \
    &lt;span class="nv"&gt;NO_PYTHON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YesPlease &lt;span class="nv"&gt;NO_CURL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YesPlease &lt;span class="nv"&gt;NO_EXPAT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YesPlease
$ ./git --version
git version 2.56.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;git history&lt;/code&gt; is explicitly marked experimental in its own man page: "THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE." It currently has four subcommands: &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;fixup&lt;/code&gt;, &lt;code&gt;reword&lt;/code&gt;, &lt;code&gt;split&lt;/code&gt;. I focused on &lt;code&gt;drop&lt;/code&gt;, which removes a commit and replays everything after it onto the commit's parent.&lt;/p&gt;

&lt;h2&gt;
  
  
  The benchmark
&lt;/h2&gt;

&lt;p&gt;For each test size, I built a fresh non-bare repo with a root commit, a target commit to drop, and N descendant commits, each touching a shared file and a unique file so the replay has to do real diff work. I then cloned it &lt;code&gt;--bare&lt;/code&gt; twice, so the two methods started from byte-identical history:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Old way&lt;/strong&gt;: &lt;code&gt;git worktree add&lt;/code&gt; a linked worktree off the bare repo, run &lt;code&gt;git rebase --onto &amp;lt;target&amp;gt;^ &amp;lt;target&amp;gt; main&lt;/code&gt;, remove the worktree.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New way&lt;/strong&gt;: &lt;code&gt;git history drop &amp;lt;target&amp;gt; --update-refs=branches&lt;/code&gt; directly against the bare repo, no worktree at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Three trials per size, wall-clock &lt;code&gt;date +%s.%N&lt;/code&gt; around each run:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Descendant commits&lt;/th&gt;
&lt;th&gt;Old way (rebase), avg&lt;/th&gt;
&lt;th&gt;range&lt;/th&gt;
&lt;th&gt;New way (history drop), avg&lt;/th&gt;
&lt;th&gt;range&lt;/th&gt;
&lt;th&gt;Ratio&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;1.418s&lt;/td&gt;
&lt;td&gt;1.364–1.473s&lt;/td&gt;
&lt;td&gt;0.035s&lt;/td&gt;
&lt;td&gt;0.034–0.037s&lt;/td&gt;
&lt;td&gt;40.7×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;7.121s&lt;/td&gt;
&lt;td&gt;7.014–7.183s&lt;/td&gt;
&lt;td&gt;0.092s&lt;/td&gt;
&lt;td&gt;0.084–0.097s&lt;/td&gt;
&lt;td&gt;77.5×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;td&gt;26.525s&lt;/td&gt;
&lt;td&gt;25.504–27.296s&lt;/td&gt;
&lt;td&gt;0.362s&lt;/td&gt;
&lt;td&gt;0.287–0.414s&lt;/td&gt;
&lt;td&gt;73.2×&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both methods produced the same resulting tree. I checked the tree hash of &lt;code&gt;main&lt;/code&gt; after each run on a smaller repo and they matched exactly, even though the individual commit hashes differed (new commit timestamps, naturally):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git -C old.git rev-parse main^&lt;span class="o"&gt;{&lt;/span&gt;tree&lt;span class="o"&gt;}&lt;/span&gt;
fadfb2c2c2f23eb52db063920d6e686fb90ea5f2
$ git -C new.git rev-parse main^&lt;span class="o"&gt;{&lt;/span&gt;tree&lt;span class="o"&gt;}&lt;/span&gt;
fadfb2c2c2f23eb52db063920d6e686fb90ea5f2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So this isn't a case of the new command cutting corners. It gets to the same place, just much faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the 70× actually comes from
&lt;/h2&gt;

&lt;p&gt;My first guess was that the saving was mostly in skipping &lt;code&gt;git worktree add&lt;/code&gt; and the later &lt;code&gt;git worktree remove&lt;/code&gt;. I timed those in isolation on the 400-commit case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ &lt;span class="k"&gt;time&lt;/span&gt; git -C old.git worktree add -q /tmp/wt main
real    0m0.017s
$ &lt;span class="k"&gt;time&lt;/span&gt; git -C old.git worktree remove /tmp/wt --force
real    0m0.009s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Together that's 26 milliseconds out of a 25-second run. The worktree setup isn't the story. I then timed the rebase itself, in isolation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ &lt;span class="k"&gt;time&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /tmp/wt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git rebase --quiet --onto &lt;span class="s2"&gt;"$target^"&lt;/span&gt; &lt;span class="s2"&gt;"$target"&lt;/span&gt; main&lt;span class="o"&gt;)&lt;/span&gt;
real    0m25.199s
user    0m5.844s
sys     0m6.047s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Six seconds of system time to replay 400 commits is the giveaway. &lt;code&gt;git rebase --onto&lt;/code&gt; cherry-picks each commit one at a time, and each cherry-pick updates the index and the worktree, even though nothing outside the final result is ever going to be looked at. &lt;code&gt;git history drop&lt;/code&gt; never touches a working tree for &lt;code&gt;drop&lt;/code&gt;, &lt;code&gt;reword&lt;/code&gt;, or &lt;code&gt;split&lt;/code&gt; — the docs say so directly, and the timing backs it up. It operates purely on objects in &lt;code&gt;.git&lt;/code&gt;, so the cost scales with the actual diff work, not with filesystem writes per commit.&lt;/p&gt;

&lt;h2&gt;
  
  
  What else it does that rebase doesn't
&lt;/h2&gt;

&lt;p&gt;Two differences surprised me enough to check directly, with exact output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It updates every branch that descends from the dropped commit, not just the one you're on.&lt;/strong&gt; I created &lt;code&gt;main&lt;/code&gt; and a &lt;code&gt;feature&lt;/code&gt; branch both pointing past a shared &lt;code&gt;TARGET&lt;/code&gt; commit, then ran one &lt;code&gt;git history drop&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git log --oneline main feature
&lt;span class="c"&gt;# before: main at d2, feature at d1, both past TARGET&lt;/span&gt;
$ git &lt;span class="nb"&gt;history&lt;/span&gt; drop &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;target-hash&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --update-refs=branches
$ git log --oneline main
52b8e52 d2
1ef9a67 d1
dab8608 root
$ git log --oneline feature
1ef9a67 d1
dab8608 root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both branches moved. A plain rebase only ever rewrites the branch you're currently on; cleaning up a second branch would be a second, separate rebase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It does not run hooks.&lt;/strong&gt; I put an executable &lt;code&gt;post-rewrite&lt;/code&gt; hook in a test repo that appends to a log file. &lt;code&gt;git history drop&lt;/code&gt; never triggered it. The same repo, same hook, run through &lt;code&gt;git rebase --onto&lt;/code&gt; instead, fired it immediately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git &lt;span class="nb"&gt;history&lt;/span&gt; drop &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;target-hash&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --update-refs=head
$ cat hook.log
cat: hook.log: No such file or directory

$ git rebase --quiet --onto HEAD~2 HEAD~1 main
$ cat hook.log
POST-REWRITE FIRED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your team relies on &lt;code&gt;post-rewrite&lt;/code&gt; for anything — notifying a bot, updating a cache, re-running a linter — switching a script from rebase to &lt;code&gt;git history drop&lt;/code&gt; will silently stop firing it. The man page does say hooks aren't run "at the current point in time," with a note that this may change, so don't treat this as permanent, but it's true today.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses
&lt;/h2&gt;

&lt;p&gt;I tried the three things the docs say are off-limits, to see the actual errors rather than take the documentation's word for it.&lt;/p&gt;

&lt;p&gt;Dropping the root commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git &lt;span class="nb"&gt;history&lt;/span&gt; drop &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;root-hash&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --update-refs=branches
error: cannot drop root commit 7b93b486e52f50f22330e79a04f5da05e7457734: it has no parent to replay onto
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dropping a merge commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git &lt;span class="nb"&gt;history&lt;/span&gt; drop &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;merge-hash&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --update-refs=branches
error: cannot drop merge commit: 292f3c6e56c3001b8ea93ccc69751f27b8fd8424
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both refusals are immediate and exit non-zero (255 in my build). Neither one leaves anything behind to clean up.&lt;/p&gt;

&lt;p&gt;The more interesting case is a drop that would cause a conflict during replay. I built a commit chain where the target commit changes a line and a later commit changes the same line again, which is exactly what would conflict:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git &lt;span class="nb"&gt;history&lt;/span&gt; drop &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;target-hash&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --update-refs=branches
error: failed replaying descendants
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I checked the repo state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git status --short
$ ls .git &lt;span class="o"&gt;|&lt;/span&gt; grep -i rebase
&lt;span class="o"&gt;(&lt;/span&gt;no rebase state directory&lt;span class="o"&gt;)&lt;/span&gt;
$ git log --oneline
e6e5ca7 d1
bdbfea2 TARGET
276c6de root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing changed. No conflict markers in any file, no &lt;code&gt;rebase-merge&lt;/code&gt; directory, no half-finished state. History is exactly as it was before I ran the command. That's the actual payoff of "history rewrites are not intended to be stateful operations," which the man page states as a design limitation rather than a feature — but from where I'm sitting, a command that fails all-or-nothing is a feature. Compare that to an interactive rebase hitting the same conflict: it stops mid-sequence with the working tree dirty, and you either resolve it by hand or run &lt;code&gt;git rebase --abort&lt;/code&gt;. &lt;code&gt;git history drop&lt;/code&gt; skips that step entirely by refusing to start down a road it can't finish.&lt;/p&gt;

&lt;h2&gt;
  
  
  The dry-run output is genuinely a diff you can apply
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;--dry-run&lt;/code&gt; doesn't just print a preview; it prints &lt;code&gt;git update-ref --stdin&lt;/code&gt; syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git &lt;span class="nb"&gt;history&lt;/span&gt; drop &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;target-hash&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --dry-run --update-refs=branches
update refs/heads/main f5f696ff8266f3709b306457024cecbedb25275b ab0b41479b899b357f0cdbd462e0ea9041aba9c9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I piped that straight into &lt;code&gt;update-ref&lt;/code&gt; and it worked exactly as the real run would have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ git &lt;span class="nb"&gt;history&lt;/span&gt; drop &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;target-hash&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --dry-run --update-refs=branches &lt;span class="o"&gt;|&lt;/span&gt; git update-ref --stdin
$ git log --oneline main
b2f5b62 d1
523c749 root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's a genuinely useful property if you want to review a rewrite before committing to it — generate the objects, inspect the proposed ref moves, then apply them with a separate, auditable command.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My first pass at the benchmark used &lt;code&gt;git history drop --quiet&lt;/code&gt; to suppress output, matching the &lt;code&gt;--quiet&lt;/code&gt; I was already passing to &lt;code&gt;git rebase&lt;/code&gt;. &lt;code&gt;git history drop&lt;/code&gt; doesn't have a &lt;code&gt;--quiet&lt;/code&gt; flag, so every "new way" run failed immediately with &lt;code&gt;error: unknown option 'quiet'&lt;/code&gt; and a usage message. Because I was piping stderr into a log file and only checking the elapsed time, the failed runs looked like spectacular successes — 0.003 seconds to drop 100 commits. I didn't believe that number, which is the only reason I caught it: I diffed the resulting commit hash against the pre-run hash and found they were identical, meaning nothing had happened at all. After that I stopped suppressing stderr in any timing run and let failures show up as failures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;

&lt;p&gt;This needs Git built from the &lt;code&gt;v2.56.0&lt;/code&gt; tag, as above. The full benchmark script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -euo pipefail
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/path/to/git-src:&lt;span class="nv"&gt;$PATH&lt;/span&gt;
&lt;span class="nv"&gt;WORK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;mktemp -d&lt;span class="o"&gt;)&lt;/span&gt;

make_src_repo &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt; &lt;span class="nv"&gt;dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;
  git init -q -b main &lt;span class="s2"&gt;"$dir"&lt;/span&gt;
  &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"$dir"&lt;/span&gt;
   git config user.email a@b.c&lt;span class="o"&gt;;&lt;/span&gt; git config user.name &lt;span class="nb"&gt;test&lt;/span&gt;
   &lt;span class="nb"&gt;echo&lt;/span&gt; root &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; root.txt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git add root.txt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit -q -m root
   &lt;span class="nb"&gt;echo&lt;/span&gt; t &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; target.txt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git add target.txt &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git commit -q -m TARGET
   git rev-parse HEAD &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /tmp/target_hash.txt
   &lt;span class="nb"&gt;echo&lt;/span&gt; start &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; shared.txt
   &lt;span class="k"&gt;for&lt;/span&gt; i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;seq 1 &lt;span class="s2"&gt;"$n"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
     &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"line$i"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; shared.txt&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"f$i"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"f$i.txt"&lt;/span&gt;
     git add shared.txt &lt;span class="s2"&gt;"f$i.txt"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; git commit -q -m &lt;span class="s2"&gt;"d$i"&lt;/span&gt;
   &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; n &lt;span class="k"&gt;in&lt;/span&gt; 20 100 400&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  make_src_repo &lt;span class="s2"&gt;"$n"&lt;/span&gt; &lt;span class="s2"&gt;"$WORK/src"&lt;/span&gt;
  &lt;span class="nv"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;cat /tmp/target_hash.txt&lt;span class="o"&gt;)&lt;/span&gt;

  git clone -q --bare &lt;span class="s2"&gt;"$WORK/src"&lt;/span&gt; &lt;span class="s2"&gt;"$WORK/old.git"&lt;/span&gt;
  &lt;span class="nv"&gt;wt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$WORK/wt"&lt;/span&gt;
  git -C &lt;span class="s2"&gt;"$WORK/old.git"&lt;/span&gt; worktree add -q &lt;span class="s2"&gt;"$wt"&lt;/span&gt; main
  &lt;span class="nv"&gt;t0&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date +%s.%N&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"$wt"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; git rebase --quiet --onto &lt;span class="s2"&gt;"${target}^"&lt;/span&gt; &lt;span class="s2"&gt;"$target"&lt;/span&gt; main&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="nv"&gt;t1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date +%s.%N&lt;span class="o"&gt;)&lt;/span&gt;
  git -C &lt;span class="s2"&gt;"$WORK/old.git"&lt;/span&gt; worktree remove &lt;span class="s2"&gt;"$wt"&lt;/span&gt; --force
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"n=$n old=$(echo "&lt;/span&gt;&lt;span class="nv"&gt;$t1&lt;/span&gt; - &lt;span class="nv"&gt;$t0&lt;/span&gt;&lt;span class="s2"&gt;" | bc)s"&lt;/span&gt;

  git clone -q --bare &lt;span class="s2"&gt;"$WORK/src"&lt;/span&gt; &lt;span class="s2"&gt;"$WORK/new.git"&lt;/span&gt;
  &lt;span class="nv"&gt;t0&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date +%s.%N&lt;span class="o"&gt;)&lt;/span&gt;
  git -C &lt;span class="s2"&gt;"$WORK/new.git"&lt;/span&gt; &lt;span class="nb"&gt;history&lt;/span&gt; drop &lt;span class="s2"&gt;"$target"&lt;/span&gt; --update-refs=branches
  &lt;span class="nv"&gt;t1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date +%s.%N&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"n=$n new=$(echo "&lt;/span&gt;&lt;span class="nv"&gt;$t1&lt;/span&gt; - &lt;span class="nv"&gt;$t0&lt;/span&gt;&lt;span class="s2"&gt;" | bc)s"&lt;/span&gt;

  rm -rf &lt;span class="s2"&gt;"$WORK/src"&lt;/span&gt; &lt;span class="s2"&gt;"$WORK/old.git"&lt;/span&gt; &lt;span class="s2"&gt;"$WORK/new.git"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran this three times per size on an otherwise idle machine; your absolute numbers will depend on disk and CPU, but the ratio between the two methods should hold, since the gap comes from per-commit working-tree writes, not from anything specific to my hardware.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do with this
&lt;/h2&gt;

&lt;p&gt;If you ever script history rewrites against a bare repo — cleaning up a leaked secret from a shared repository, dropping a bad commit from a long-lived integration branch, anything that currently involves a throwaway clone or worktree — try &lt;code&gt;git history drop&lt;/code&gt; instead, but build it from source first, since it isn't in a stable release that's reached your distribution yet. Don't move anything that depends on &lt;code&gt;post-rewrite&lt;/code&gt; firing until you've checked for that dependency, and don't reach for it on a history that contains merge commits: it will refuse, today, with no workaround beyond &lt;code&gt;git rebase --rebase-merges&lt;/code&gt;. Treat the command as what its own man page calls it — experimental — and keep &lt;code&gt;git rebase&lt;/code&gt; as your fallback for anything it refuses.&lt;/p&gt;

</description>
      <category>git</category>
      <category>devops</category>
      <category>performance</category>
      <category>cli</category>
    </item>
    <item>
      <title>ClickHouse 26.10's string filter during scan cuts a selective LIKE query's memory 25-fold</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Thu, 12 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/clickhouse-2610s-string-filter-during-scan-cuts-a-selective-like-querys-memory-25-fold-228j</link>
      <guid>https://dev.to/alexgeorgiev17/clickhouse-2610s-string-filter-during-scan-cuts-a-selective-like-querys-memory-25-fold-228j</guid>
      <description>&lt;p&gt;A &lt;code&gt;LIKE&lt;/code&gt; query against ten million rows used 37.6MB of peak memory on ClickHouse 26.9. The same table, the same query, same hardware, on 26.10 released six days ago: 1.48MB. Nothing else about the query changed.&lt;/p&gt;

&lt;p&gt;ClickHouse 26.10 shipped on 6 November 2026 with a new setting, &lt;code&gt;apply_string_filters_during_scan&lt;/code&gt;, on by default. It pushes substring search conditions down into the column scan itself, so rows that don't match never get fully materialised. I wanted to know what that's actually worth, where it stops working, and what a reader would hit if they relied on it without reading the fine print.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the setting does
&lt;/h2&gt;

&lt;p&gt;The description in &lt;code&gt;system.settings&lt;/code&gt; is unusually precise for a ClickHouse setting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When a PREWHERE condition contains a conjunct that searches for a non-empty
substring in a String column (LIKE, position, startsWith, endsWith, or
equality with a non-empty string), the reader checks every value against
this condition during deserialization and reads non-matching values as
empty strings.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It also says the filter "is disabled adaptively at runtime if it turns out to be non-selective." That line turned out to matter a lot once I started testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building something to test against
&lt;/h2&gt;

&lt;p&gt;I generated a ten-million-row &lt;code&gt;MergeTree&lt;/code&gt; table with a &lt;code&gt;body&lt;/code&gt; column of roughly 1.3KB of repeated filler text per row, with one row in a hundred containing the word "wonderful" somewhere in the middle. I deliberately made the matching and non-matching rows the same length, so any memory difference would come from selectivity, not from one branch of the data happening to be shorter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;reviews&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nc"&gt;UInt64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;ENGINE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MergeTree&lt;/span&gt; &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;
&lt;span class="no"&gt;SETTINGS&lt;/span&gt; &lt;span class="n"&gt;min_bytes_for_wide_part&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min_rows_for_wide_part&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;reviews&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="nb"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'this product was absolutely wonderful and exceeded expectations. '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'filler padding text to pad out the row length evenly '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ordinary filler padding text that never matches the needle word '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="nf"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10000000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's 103MB on disk, 1% of rows matching &lt;code&gt;LIKE '%wonderful%'&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The headline number, checked against the previous version
&lt;/h2&gt;

&lt;p&gt;Toggling a setting within one binary can hide a difference if the code path isn't really what you think it is. So I ran the same query three ways: ClickHouse 26.9.27.3 (which doesn't have this setting at all), 26.10.3.7 with it forced off, and 26.10.3.7 at its default. Three runs each, single-threaded for determinism, peak memory read from &lt;code&gt;system.query_log.memory_usage&lt;/code&gt; after &lt;code&gt;SYSTEM FLUSH LOGS&lt;/code&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;26.9 (no setting exists)&lt;/th&gt;
&lt;th&gt;26.10, setting off&lt;/th&gt;
&lt;th&gt;26.10, setting on (default)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Peak memory&lt;/td&gt;
&lt;td&gt;37.6MB&lt;/td&gt;
&lt;td&gt;37.7MB&lt;/td&gt;
&lt;td&gt;1.48MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Duration&lt;/td&gt;
&lt;td&gt;1.48–1.97s&lt;/td&gt;
&lt;td&gt;1.51–1.63s&lt;/td&gt;
&lt;td&gt;0.97–1.01s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;26.9 and 26.10-with-the-setting-off land in the same place, which is what you'd want to see: it confirms the setting, not some other change in the release, is doing the work. At 1% selectivity, the win is roughly 25 times less memory and about 35-40% faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  The number that argues against it
&lt;/h2&gt;

&lt;p&gt;The settings description says the filter gets "disabled adaptively" when it isn't selective. I tested that directly by querying for &lt;code&gt;LIKE '%filler%'&lt;/code&gt; against the same table — a word that appears in both the matching and non-matching rows, so it matches 100% of the ten million rows:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;setting on&lt;/th&gt;
&lt;th&gt;setting off&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Peak memory&lt;/td&gt;
&lt;td&gt;25.6MB&lt;/td&gt;
&lt;td&gt;37.7MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Duration&lt;/td&gt;
&lt;td&gt;1017–1121ms&lt;/td&gt;
&lt;td&gt;879–1074ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;It did not disable. Memory usage with the setting on was still lower — about 32% lower, not 25x — but the time advantage disappeared entirely; across three runs each, the "on" case was not reliably faster than "off," and in two of three comparisons it was a touch slower. "Disabled adaptively" reads like the optimiser backs off completely once selectivity drops. What I actually saw was a much smaller, partial benefit that persists even at 100% selectivity, with no time benefit at all. If you're deciding whether to rely on this for a non-selective filter, don't: there's a small memory saving and no speed saving.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses
&lt;/h2&gt;

&lt;p&gt;The settings description names exactly which predicates qualify: &lt;code&gt;LIKE&lt;/code&gt;, &lt;code&gt;position&lt;/code&gt;, &lt;code&gt;startsWith&lt;/code&gt;, &lt;code&gt;endsWith&lt;/code&gt;, and equality with a non-empty string. I tried two predicates that look similar but aren't on that list.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;match()&lt;/code&gt;, ClickHouse's regex function, got nothing:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;predicate&lt;/th&gt;
&lt;th&gt;setting on&lt;/th&gt;
&lt;th&gt;setting off&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;match(body, 'wonderful')&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;37.71MB&lt;/td&gt;
&lt;td&gt;37.71MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Identical memory, both ways. If you're using &lt;code&gt;match()&lt;/code&gt; because you reached for regex out of habit, switching to &lt;code&gt;LIKE&lt;/code&gt; where the pattern allows it is worth doing in 26.10 specifically, because it's the only one of the two that benefits here.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NOT LIKE&lt;/code&gt;, excluding the same 1%-selective term, also got nothing:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;predicate&lt;/th&gt;
&lt;th&gt;setting on&lt;/th&gt;
&lt;th&gt;setting off&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;body NOT LIKE '%wonderful%'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;37.71MB&lt;/td&gt;
&lt;td&gt;37.71MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That one makes sense once you think about it: excluding a rare term means 99% of rows pass the filter, so from the optimiser's point of view it's a non-selective predicate, consistent with the adaptive-disable behaviour I saw above, just more completely disabled this time.&lt;/p&gt;

&lt;p&gt;The more surprising refusal was plain equality. The docs list "equality with a non-empty string" as covered, so I expected &lt;code&gt;WHERE body = '&amp;lt;the full matching string&amp;gt;'&lt;/code&gt; to behave like &lt;code&gt;LIKE&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;predicate&lt;/th&gt;
&lt;th&gt;setting on&lt;/th&gt;
&lt;th&gt;setting off&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;WHERE body = '...'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;37.73MB&lt;/td&gt;
&lt;td&gt;37.73MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;No difference at all — the exact same non-result as &lt;code&gt;match()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My first reaction to that equality result was to conclude the docs were simply wrong about equality being covered. I was about to write that up as the headline refusal finding. Before doing that I ran &lt;code&gt;EXPLAIN actions=1&lt;/code&gt; on both queries to see what was actually happening at the plan level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- the LIKE query&lt;/span&gt;
&lt;span class="nc"&gt;Prewhere&lt;/span&gt; &lt;span class="k"&gt;filter&lt;/span&gt;
&lt;span class="nc"&gt;Prewhere&lt;/span&gt; &lt;span class="k"&gt;filter&lt;/span&gt; &lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%wonderful%'&lt;/span&gt;

&lt;span class="c1"&gt;-- the equality query&lt;/span&gt;
└──&lt;span class="k"&gt;Filter&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;Change&lt;/span&gt; &lt;span class="k"&gt;column&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="k"&gt;column&lt;/span&gt; &lt;span class="n"&gt;identifiers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;LIKE&lt;/code&gt; condition gets automatically promoted from &lt;code&gt;WHERE&lt;/code&gt; into &lt;code&gt;PREWHERE&lt;/code&gt;. The equality condition does not — it stays a plain post-scan &lt;code&gt;Filter&lt;/code&gt;, and &lt;code&gt;apply_string_filters_during_scan&lt;/code&gt; only does anything inside &lt;code&gt;PREWHERE&lt;/code&gt;. My test wasn't exercising the feature at all for equality; it was testing a query shape that never reaches the optimisation in the first place. The docs are more precise than I'd given them credit for: "equality with a constant string is not moved" into &lt;code&gt;PREWHERE&lt;/code&gt; by this setting — it only applies "when it is already in &lt;code&gt;PREWHERE&lt;/code&gt;." I'd misread "not moved for this reason" as "not accelerated," when it actually means the move itself doesn't happen, but the acceleration still does if you put it there yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  The workaround, and it works
&lt;/h2&gt;

&lt;p&gt;Rewriting the same query with an explicit &lt;code&gt;PREWHERE&lt;/code&gt; instead of &lt;code&gt;WHERE&lt;/code&gt; recovers the benefit completely:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;predicate&lt;/th&gt;
&lt;th&gt;setting on&lt;/th&gt;
&lt;th&gt;setting off&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PREWHERE body = '...'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1.50MB&lt;/td&gt;
&lt;td&gt;17.82MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That's the real number for equality: about 12 times less memory, once the condition is actually where the setting looks for it. The practical takeaway is specific and actionable: an ordinary analyst typing &lt;code&gt;WHERE col = 'value'&lt;/code&gt; against a wide text column gets nothing from this release's headline memory improvement, regardless of the setting, unless they write &lt;code&gt;PREWHERE&lt;/code&gt; themselves. &lt;code&gt;LIKE&lt;/code&gt; doesn't have this problem because ClickHouse promotes it automatically; equality doesn't, and the gap between "works for me" and "works for you" here is a single keyword most people won't think to add.&lt;/p&gt;

&lt;h2&gt;
  
  
  Under concurrency
&lt;/h2&gt;

&lt;p&gt;I ran the original 1%-selective &lt;code&gt;LIKE&lt;/code&gt; query from ten concurrent &lt;code&gt;clickhouse-client&lt;/code&gt; processes, default threading, timing the whole batch:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;setting on&lt;/th&gt;
&lt;th&gt;setting off&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Wall time, run 1&lt;/td&gt;
&lt;td&gt;3.18s&lt;/td&gt;
&lt;td&gt;6.54s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Wall time, run 2&lt;/td&gt;
&lt;td&gt;3.03s&lt;/td&gt;
&lt;td&gt;7.17s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The gap held up under load — if anything it widened slightly. Sampling the container's memory with &lt;code&gt;docker stats&lt;/code&gt; during the burst showed a peak around 763MB with the setting on against roughly 1.3GB with it off, in line with ten queries each carrying their own ~37MB-versus-~1.5MB difference plus server overhead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watching it in production
&lt;/h2&gt;

&lt;p&gt;There's no dedicated counter for this specific setting in &lt;code&gt;system.events&lt;/code&gt;, but the ordinary &lt;code&gt;query_log&lt;/code&gt; columns show it per query without any extra instrumentation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;query_duration_ms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;memory_usage&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;query_log&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;query_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;id&amp;gt;'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'QueryFinish'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're upgrading and want to see the effect on your own workload rather than trust a release note, that's the column to watch before and after.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;

&lt;p&gt;This needs Docker with a running daemon. Each image is a few hundred megabytes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run -d --name ch26 -p 18123:8123 \
  -e &lt;span class="nv"&gt;CLICKHOUSE_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;test1234 clickhouse/clickhouse-server:26.10

docker &lt;span class="nb"&gt;exec&lt;/span&gt; ch26 clickhouse-client --password test1234 --multiquery --query &lt;span class="s2"&gt;"
CREATE TABLE reviews (id UInt64, body String)
ENGINE = MergeTree ORDER BY id
SETTINGS min_bytes_for_wide_part = 0, min_rows_for_wide_part = 0;

INSERT INTO reviews
SELECT number,
  if(number % 100 = 0,
     concat('this product was absolutely wonderful and exceeded expectations. ',
            repeat('filler padding text to pad out the row length evenly ', 20)),
     repeat('ordinary filler padding text that never matches the needle word ', 20))
FROM numbers(10000000);
"&lt;/span&gt;

&lt;span class="c"&gt;# compare memory with the setting on vs off&lt;/span&gt;
docker &lt;span class="nb"&gt;exec&lt;/span&gt; ch26 clickhouse-client --password test1234 --query &lt;span class="s2"&gt;"
SELECT count() FROM reviews WHERE body LIKE '%wonderful%'
SETTINGS apply_string_filters_during_scan = 1, max_threads = 1 FORMAT Null"&lt;/span&gt;
docker &lt;span class="nb"&gt;exec&lt;/span&gt; ch26 clickhouse-client --password test1234 --query &lt;span class="s2"&gt;"SYSTEM FLUSH LOGS"&lt;/span&gt;
docker &lt;span class="nb"&gt;exec&lt;/span&gt; ch26 clickhouse-client --password test1234 --query &lt;span class="s2"&gt;"
SELECT query_duration_ms, memory_usage FROM system.query_log
WHERE query LIKE '%wonderful%' AND type = 'QueryFinish'
ORDER BY event_time DESC LIMIT 1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change &lt;code&gt;apply_string_filters_during_scan&lt;/code&gt; to &lt;code&gt;0&lt;/code&gt; and re-run to see the before-and-after yourself. I ran every command in this post against the same container and dataset the numbers above came from.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do with this
&lt;/h2&gt;

&lt;p&gt;If you're already running 26.10, check which of your text filters are written as &lt;code&gt;LIKE&lt;/code&gt;, &lt;code&gt;startsWith&lt;/code&gt;, or &lt;code&gt;endsWith&lt;/code&gt; against a &lt;code&gt;MergeTree&lt;/code&gt; table — those get this for free, with no code change. If you have hot queries written as &lt;code&gt;WHERE col = 'value'&lt;/code&gt; against a wide String column, check &lt;code&gt;EXPLAIN actions=1&lt;/code&gt; for a &lt;code&gt;Prewhere filter&lt;/code&gt; node before assuming you're getting the same win; if it's a plain &lt;code&gt;Filter&lt;/code&gt; instead, rewriting as &lt;code&gt;PREWHERE col = 'value'&lt;/code&gt; is a one-word change with a real memory payoff on this release. And if your filter is non-selective — excluding a rare value, or matching most of the table — don't expect the default to save you much; test your own selectivity rather than assume the setting degrades gracefully to "no worse than before," because on a 100%-selective case it still used less memory but gained no speed at all.&lt;/p&gt;

</description>
      <category>clickhouse</category>
      <category>database</category>
      <category>performance</category>
      <category>devops</category>
    </item>
    <item>
      <title>DuckDB 2.0's quack server lets ten writers share one file for under 2ms a query</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Wed, 11 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/duckdb-20s-quack-server-lets-ten-writers-share-one-file-for-under-2ms-a-query-1ged</link>
      <guid>https://dev.to/alexgeorgiev17/duckdb-20s-quack-server-lets-ten-writers-share-one-file-for-under-2ms-a-query-1ged</guid>
      <description>&lt;p&gt;Try to open a DuckDB file from two processes at once and you get this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_duckdb.IOException: IO Error: Could not set lock on file "server.duckdb":
Conflicting lock is held in /usr/bin/python3.11 (PID 1355).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That has been true since the beginning. DuckDB is an in-process database: one file, one writer, full stop. DuckDB 2.0, which went GA on 21 October 2026, ships an extension called &lt;code&gt;quack&lt;/code&gt; that turns a running DuckDB process into a small network server other DuckDB processes can connect to. I wanted to know whether that actually gets you past the lock, what it costs per query, and what it still refuses to do.&lt;/p&gt;

&lt;p&gt;I ran DuckDB 2.0.0 through the Python client (&lt;code&gt;pip install duckdb==2.0.0&lt;/code&gt;), started a server on a table with a million rows, and hit it from separate Python processes acting as independent clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting it up
&lt;/h2&gt;

&lt;p&gt;The server side loads the extension and calls &lt;code&gt;quack_serve&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;duckdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'server.duckdb'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"INSTALL quack; LOAD quack;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CREATE TABLE t AS SELECT range AS i, 'row_'||range AS s FROM range(1000000)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CALL quack_serve('quack:localhost:9494', token='testtoken123')"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A client attaches to it as a remote database and routes its whole session there with &lt;code&gt;CONNECT&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;duckdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"INSTALL quack; LOAD quack;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ATTACH 'quack:localhost:9494' AS srv (TOKEN 'testtoken123')"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CONNECT srv"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SELECT count(*) FROM t"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# [(1000000,)]&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"DISCONNECT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;CONNECT&lt;/code&gt; takes about 3ms the first time and the client then talks to the server for every query until it disconnects.&lt;/p&gt;

&lt;h2&gt;
  
  
  The lock is still there, and that's the point
&lt;/h2&gt;

&lt;p&gt;Opening &lt;code&gt;server.duckdb&lt;/code&gt; directly from a second process while the server holds it still fails with the exact error above. Quack doesn't touch DuckDB's file-locking model at all. What it does is give you a second door into the one process that is allowed to hold the write lock, so that ten processes can write through that one door instead of fighting over the file.&lt;/p&gt;

&lt;p&gt;I also checked whether the lock problem was ever really about reads. It isn't: with no writer active, two processes can open the same file with &lt;code&gt;read_only=True&lt;/code&gt; at the same time and both query it fine. That already worked before 2.0. Quack's actual contribution is concurrent &lt;strong&gt;writes&lt;/strong&gt;, not concurrent reads, which is a narrower claim than "multiple processes can now use one DuckDB file" might suggest.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writes that used to be impossible
&lt;/h2&gt;

&lt;p&gt;I ran 10 client processes, each opening its own connection through &lt;code&gt;CONNECT&lt;/code&gt; and firing 100 single-row inserts, 1,000 inserts in total.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setup&lt;/th&gt;
&lt;th&gt;Errors&lt;/th&gt;
&lt;th&gt;Rows landed&lt;/th&gt;
&lt;th&gt;Distinct (client, seq) pairs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2 processes, direct file open&lt;/td&gt;
&lt;td&gt;1 (lock error, immediate)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10 clients via quack &lt;code&gt;CONNECT&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1,000&lt;/td&gt;
&lt;td&gt;1,000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every insert landed, nothing was lost or duplicated, and the server-side count matched the client-side count exactly across three repeats of this test. That is the headline: a workload that used to be impossible to run from more than one process at a time now runs correctly from ten.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concurrency doesn't scale the way I expected
&lt;/h2&gt;

&lt;p&gt;I measured throughput for the same 1,000 inserts split across 1, 5, 10 and 20 concurrent clients, three full sweeps:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Clients&lt;/th&gt;
&lt;th&gt;Run 1&lt;/th&gt;
&lt;th&gt;Run 2&lt;/th&gt;
&lt;th&gt;Run 3&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1 (serial)&lt;/td&gt;
&lt;td&gt;401/s&lt;/td&gt;
&lt;td&gt;380/s&lt;/td&gt;
&lt;td&gt;348/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;692/s&lt;/td&gt;
&lt;td&gt;735/s&lt;/td&gt;
&lt;td&gt;655/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;542/s&lt;/td&gt;
&lt;td&gt;570/s&lt;/td&gt;
&lt;td&gt;508/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;362/s&lt;/td&gt;
&lt;td&gt;332/s&lt;/td&gt;
&lt;td&gt;342/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Throughput peaks at 5 concurrent clients, then falls off. At 20 clients it drops back to roughly the same number as a single client running everything serially, sometimes below it. I didn't expect that, so I reran the whole sweep twice more to make sure it wasn't a fluke. It wasn't. DuckDB still executes writes against one file one at a time internally; quack's connection handling adds its own overhead on top, and past a handful of clients that overhead eats whatever the server-side queueing gains you. If your workload is many short-lived writers, five seems to be roughly where this particular setup stopped paying off and started costing more than it saved.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a query costs going through the wire
&lt;/h2&gt;

&lt;p&gt;Even on loopback, going through the server instead of talking to the file in-process adds a tax on every query, measured over 200 runs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Query&lt;/th&gt;
&lt;th&gt;In-process&lt;/th&gt;
&lt;th&gt;Via quack &lt;code&gt;CONNECT&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;SELECT 1&lt;/code&gt; (median)&lt;/td&gt;
&lt;td&gt;0.25ms&lt;/td&gt;
&lt;td&gt;1.92ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;SELECT sum(i), count(*) FROM t&lt;/code&gt; (median, 1M rows)&lt;/td&gt;
&lt;td&gt;0.77ms&lt;/td&gt;
&lt;td&gt;2.42ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;SELECT * FROM t&lt;/code&gt; (full 1M rows fetched)&lt;/td&gt;
&lt;td&gt;0.334s&lt;/td&gt;
&lt;td&gt;0.391s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For small queries the absolute numbers are tiny but the ratio is large, about 7–8x for a trivial query. For a query that returns a lot of data, the gap narrows to roughly 17%, which is closer to what you'd expect from serialising a result set over HTTP instead of handing back memory directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your local tables disappear while you're connected
&lt;/h2&gt;

&lt;p&gt;This one surprised me. I created a local table, then ran &lt;code&gt;CONNECT&lt;/code&gt; to the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CatalogException: Catalog Error: Table with name local_only does not exist!
Did you mean "pg_collation"?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I tried qualifying it explicitly with the schema name DuckDB normally uses for the default database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CatalogException: Catalog Error: Table with name "memory.local_only" does not
exist because schema "memory" does not exist.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both failed. While &lt;code&gt;CONNECT&lt;/code&gt;-ed, the local catalog isn't just deprioritised, it's gone from view entirely, and there's no prefix that gets it back. &lt;code&gt;DISCONNECT&lt;/code&gt; returns it immediately. If your plan was to pull a remote aggregate and join it against a local staging table in the same session, that plan doesn't work; you have to disconnect, or keep the remote session in a second connection object.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses, in its own words
&lt;/h2&gt;

&lt;p&gt;A wrong token fails immediately at &lt;code&gt;ATTACH&lt;/code&gt;, before &lt;code&gt;CONNECT&lt;/code&gt; is even called:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_duckdb.InvalidInputException: Invalid Input Error: Authentication failed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Trying to bind the server to anything other than localhost without opting in fails the same way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Invalid Input Error: Only localhost is allowed as a Quack RPC hostname by
default, set allow_other_hostname=true to override. We strongly recommend
reverse-proxying the Quack RPC when making it publicly available.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both of those matched what the docs say, which was reassuring given how much else I had to work out by trial and error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watching it from the server side
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;quack_active_connections()&lt;/code&gt; sounds like a live connection list. It's closer to a short query log: it kept rows for finished queries, with status &lt;code&gt;active&lt;/code&gt; or &lt;code&gt;finished&lt;/code&gt;, the query text, a connection id and a timestamp, even after those queries completed. Useful for seeing what clients just ran, less useful as a "who is connected right now" view, since finished work stays visible until something ages it out.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs to run
&lt;/h2&gt;

&lt;p&gt;The server process holding the million-row table idled at about 120MB RSS. Under ten concurrent clients hammering it with small queries, that rose to roughly 132MB and settled back down to about 125MB once the load finished. For a table this size, the server itself isn't the expensive part.&lt;/p&gt;

&lt;p&gt;One more thing worth knowing: killing the server process with &lt;code&gt;kill -9&lt;/code&gt; released the file lock immediately. A fresh direct connection to the same file afterwards worked on the first try, with all million rows intact. No stale lock file, no recovery step.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My first attempt at the client side used &lt;code&gt;ATTACH 'quack://localhost:9494' AS srv&lt;/code&gt;, modelled on an ordinary URL. DuckDB took that literally as a filesystem path and failed with "Cannot open file", which looked like a connection problem and sent me checking the server log for several minutes before I noticed the double slash. The actual scheme has no slashes: &lt;code&gt;quack:localhost:9494&lt;/code&gt;, the same shape DuckDB already uses for &lt;code&gt;postgres:&lt;/code&gt; and &lt;code&gt;mysql:&lt;/code&gt; connection strings. Once I matched that, everything else worked first time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 -m venv venv &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; ./venv/bin/pip install &lt;span class="nv"&gt;duckdb&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;2.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;duckdb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;duckdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'server.duckdb'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"INSTALL quack; LOAD quack;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CREATE TABLE IF NOT EXISTS t AS SELECT range AS i, 'row_'||range AS s FROM range(1000000)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CALL quack_serve('quack:localhost:9494', token='testtoken123')"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Concurrent writers, run while the server above is up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;duckdb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;make_client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;duckdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"INSTALL quack; LOAD quack;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ATTACH 'quack:localhost:9494' AS srv (TOKEN 'testtoken123')"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CONNECT srv"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt;

&lt;span class="n"&gt;setup&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CREATE TABLE IF NOT EXISTS writes (client_id INTEGER, seq INTEGER)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"DISCONNECT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;seq&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"INSERT INTO writes VALUES ({client_id}, {seq})"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"DISCONNECT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perf_counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;threads&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;th&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;threads&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;th&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;th&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;threads&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;th&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"elapsed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perf_counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;t0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What I'd do with this
&lt;/h2&gt;

&lt;p&gt;If you have a single-node analytics workload where more than one process occasionally needs to write to the same DuckDB file, quack solves a real problem that had no good answer before. I wouldn't reach for it to serve many short, latency-sensitive clients: the per-query tax is real, and my own numbers show throughput getting worse, not better, past a handful of concurrent writers. I'd also budget for the catalog isolation explicitly, since it changes how you'd structure a session that needs both local and remote tables. Test your own concurrency sweet spot before picking a client pool size; mine was 5, and I have no reason to think that number generalises to a different machine or workload.&lt;/p&gt;

</description>
      <category>database</category>
      <category>performance</category>
      <category>devops</category>
      <category>programming</category>
    </item>
    <item>
      <title>Node.js 26's Map.getOrInsertComputed is slower than the get-and-set it replaces</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Tue, 10 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/nodejs-26s-mapgetorinsertcomputed-is-slower-than-the-get-and-set-it-replaces-2i35</link>
      <guid>https://dev.to/alexgeorgiev17/nodejs-26s-mapgetorinsertcomputed-is-slower-than-the-get-and-set-it-replaces-2i35</guid>
      <description>&lt;p&gt;Node 26 shipped V8 14.6, and with it two new methods that have been asked for for years: &lt;code&gt;Map.prototype.getOrInsert()&lt;/code&gt; and &lt;code&gt;Map.prototype.getOrInsertComputed()&lt;/code&gt;. Both are meant to replace the same five-line idiom everyone has copy-pasted into a cache or a memo table at some point: look up a key, and if it isn't there, compute a default, store it, and return it.&lt;/p&gt;

&lt;p&gt;I expected the built-in version to be at least as fast as the hand-written one, since it collapses two separate Map operations into one. It is not. On a warm cache it is about 40% slower than the code it replaces.&lt;/p&gt;

&lt;p&gt;That was the first surprise. The second is more useful: the same method quietly gives you cache-stampede protection for async work, for free, with no extra code. The third is that if the computation fails, it keeps the failure cached forever, with no obvious way to know that from the method's name alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's actually new
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;getOrInsertComputed(key, callbackfn)&lt;/code&gt; checks whether &lt;code&gt;key&lt;/code&gt; is present. If it is, it returns the existing value and never touches &lt;code&gt;callbackfn&lt;/code&gt;. If it isn't, it calls &lt;code&gt;callbackfn(key)&lt;/code&gt;, stores the return value under &lt;code&gt;key&lt;/code&gt;, and returns it. &lt;code&gt;getOrInsert(key, value)&lt;/code&gt; does the same thing but takes a plain value instead of a callback. Both exist on &lt;code&gt;WeakMap&lt;/code&gt; too.&lt;/p&gt;

&lt;p&gt;I ran this on Node 26.13.0 ("Lithium", released 28 October 2026), which bundles V8 14.6.202.34:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ node --version
v26.13.0
$ node -e "console.log(process.versions.v8)"
14.6.202.34-node.40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The plain pattern it replaces looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;compute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getOrInsertComputed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;compute&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The benchmark, and the number that surprised me
&lt;/h2&gt;

&lt;p&gt;I timed both patterns under two workloads: a cold map where every one of 5,000,000 keys is new (the worst case, all misses), and a warm map where the same 1,000 keys get hit 5,000,000 times (the common case for an actual cache). Five to nine repetitions each, timestamps taken with &lt;code&gt;process.hrtime.bigint()&lt;/code&gt;, reporting the fastest and the median run.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Workload&lt;/th&gt;
&lt;th&gt;get-then-set (median)&lt;/th&gt;
&lt;th&gt;getOrInsertComputed (median)&lt;/th&gt;
&lt;th&gt;Slower by&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cold, 5M unique keys&lt;/td&gt;
&lt;td&gt;1678ms&lt;/td&gt;
&lt;td&gt;1978ms&lt;/td&gt;
&lt;td&gt;~18%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Warm, 5M calls over 1,000 keys&lt;/td&gt;
&lt;td&gt;29.7ms&lt;/td&gt;
&lt;td&gt;41.6ms&lt;/td&gt;
&lt;td&gt;~40%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I didn't believe the warm number at first, so I reran it with the two patterns alternating order across nine repetitions, to cancel out any CPU frequency or cache-warming drift, and added a third variant: a hand-written JavaScript function that does exactly what the native method does, called the same way (as an indirect function reference, not inlined in the loop):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myGetOrInsertComputed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cb&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A1 inline get+set           : min=1645.5ms  median=1772.3ms
B1 native getOrInsertComputed: min=1890.8ms  median=1952.5ms
C1 hand-rolled JS equivalent : min=1452.6ms  median=1772.4ms
B2 native getOrInsertComputed: min=1716.6ms  median=1791.7ms
A2 inline get+set           : min=1493.2ms  median=1633.7ms
C2 hand-rolled JS equivalent : min=1556.3ms  median=1640.0ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The native method was the slowest of the three in both orderings. A plain JavaScript function wrapping &lt;code&gt;get&lt;/code&gt;/&lt;code&gt;set&lt;/code&gt; and taking the same callback argument was never slower than, and sometimes faster than, the engine's own built-in. V8's JIT has had years to optimise &lt;code&gt;Map.prototype.get&lt;/code&gt; and &lt;code&gt;Map.prototype.set&lt;/code&gt; as monomorphic, inlineable calls. &lt;code&gt;getOrInsertComputed&lt;/code&gt; is new, and on this build it isn't getting the same treatment yet. I have no way to confirm the exact reason from outside the engine, but the pattern across six runs and three independent implementations was consistent enough that I'm confident it isn't noise.&lt;/p&gt;

&lt;h2&gt;
  
  
  It does buy you something real: deduplicating concurrent work
&lt;/h2&gt;

&lt;p&gt;The place &lt;code&gt;getOrInsertComputed&lt;/code&gt; earns its keep isn't raw speed, it's async correctness. If you memoise a &lt;em&gt;promise&lt;/em&gt; instead of a resolved value, calling it from several places for the same key before the first call resolves no longer triggers duplicate work, because the method inserts synchronously, before the promise settles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;fetchCalls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;fetchCalls&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolve&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`data-for-${key}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getOrInsertComputed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'y'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fetchCalls&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 'data-for-x', 'data-for-x', 'data-for-x', 'data-for-y' ] 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three concurrent calls for &lt;code&gt;x&lt;/code&gt; and one for &lt;code&gt;y&lt;/code&gt; produced exactly two calls to &lt;code&gt;fetchData&lt;/code&gt;, not four. That's the manual "in-flight promise map plus a &lt;code&gt;.finally()&lt;/code&gt; cleanup" pattern that a lot of server code hand-rolls to avoid a cache-stampede, now free with a correct, built-in single line. This is a genuine win and the strongest reason to reach for the method at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  But a failure gets cached forever
&lt;/h2&gt;

&lt;p&gt;The same property that makes deduplication work — the engine commits the promise to the map as soon as the callback returns it, without waiting to see whether it resolves or rejects — means a &lt;em&gt;rejected&lt;/em&gt; promise sits in the cache exactly like a resolved one would, and nothing evicts it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;flaky&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;attempts&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`transient failure #${attempts}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`ok on attempt ${attempts}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;tryGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`OK: ${await cache.getOrInsertComputed(key, flaky)}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`ERROR: ${e.message}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;call 1: ERROR: transient failure #1
call 2: ERROR: transient failure #1
call 3: ERROR: transient failure #1
total attempts actually made: 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;flaky()&lt;/code&gt; would have succeeded on attempt two. It never got the chance, because the first, failed attempt was already permanently cached under that key. Every later caller gets the same stale rejection, forever, until something deletes the key explicitly. If you reach for &lt;code&gt;getOrInsertComputed&lt;/code&gt; to deduplicate network calls, you need a &lt;code&gt;.catch()&lt;/code&gt; that calls &lt;code&gt;cache.delete(key)&lt;/code&gt; on the failure path yourself; the method gives you none of that for free, and nothing in its name suggests you'd need it.&lt;/p&gt;

&lt;h2&gt;
  
  
  It isn't transactional either
&lt;/h2&gt;

&lt;p&gt;I assumed the insert step was atomic with respect to the callback: whatever the callback does to the map, the final write should reflect that. It doesn't. The method remembers that the key was absent when it started, runs the callback, and then writes the callback's return value regardless of what happened to that key in between:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getOrInsertComputed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'k'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'k'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'set-during-callback'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'returned-from-callback'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'k'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// returned-from-callback returned-from-callback&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whatever the callback wrote to &lt;code&gt;'k'&lt;/code&gt; mid-flight is silently discarded and replaced by the callback's own return value. The same thing happens if the callback deletes the key instead of setting it: the delete is undone, and the key comes back holding the callback's return value. If your compute function has any side effect on the same map under the same key — which sounds like an edge case until you consider a callback that recurses, or one shared between two related caches — this is where it bites.&lt;/p&gt;

&lt;h2&gt;
  
  
  The lazy default is the whole point, and the eager one is a trap
&lt;/h2&gt;

&lt;p&gt;MDN is explicit that &lt;code&gt;getOrInsert()&lt;/code&gt; evaluates its second argument eagerly, every call, hit or miss, because that argument is just a normal JavaScript expression evaluated before the method runs — that's not a quirk of the method, it's how function calls work. &lt;code&gt;getOrInsertComputed()&lt;/code&gt; only calls its callback on a miss. The two method names are one word apart, which makes it easy to use the cheap-looking one with an expensive default by mistake. I measured the cost of making exactly that mistake, over 200,000 calls against a 100-key warm cache (so the vast majority are hits):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getOrInsert(key, expensiveDefault())        : 531.1ms, 516.5ms, 504.2ms
getOrInsertComputed(key, expensiveDefault)  : 2.8ms, 1.6ms, 1.9ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;About 270 times slower, for a cache that is already warm and should be doing almost no work. This confirms the exact warning in MDN's own docs, and it's the kind of mistake that won't show up until the default stops being a one-liner.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses
&lt;/h2&gt;

&lt;p&gt;Passing something that isn't a function as the callback throws, but the message blames the wrong thing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; m.getOrInsertComputed('k', 'not-a-function')
TypeError: Map.prototype.getOrInsertComputed is not a function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method itself is a function — I checked &lt;code&gt;typeof m.getOrInsertComputed&lt;/code&gt; first, it's &lt;code&gt;"function"&lt;/code&gt;. The actual problem is the second argument, but the error reads as if the method lookup failed, which is the one place I'd expect a newcomer to go looking in the wrong file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WeakMap&lt;/code&gt;'s versions correctly refuse primitive keys, same as every other &lt;code&gt;WeakMap&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; new WeakMap().getOrInsert('a-string-key', 1)
TypeError: Invalid value used as weak map key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That one's unsurprising, but worth confirming it wasn't quietly relaxed for the new methods. It wasn't. And if the callback throws, the map is left exactly as it was — no half-written entry, no leftover key — which is the one place everything behaved exactly as I'd have guessed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My working assumption going in was that the built-in would win on speed, since it does the lookup once internally instead of twice at the JavaScript level. I was confident enough in that assumption that my first benchmark run only tested the two patterns in one fixed order — old pattern, then new pattern — and when the new one came back slower, I didn't trust it; I assumed I'd built an unfair test, maybe because sequential integer keys from 0 upward make the two Maps grow and rehash at different points depending on which ran first. That's why the final numbers above come from a run with the order alternated nine times, plus a third, hand-rolled control implementation that rules out "the built-in is just unlucky with warm caches" as an explanation. The slowdown held up in both directions and against a plain JS equivalent, so I stopped assuming the theory was obviously true and reported what I actually measured instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;

&lt;p&gt;This needs Node 26 or later. If your system Node is older, the official binary needs no build step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s -o node26.tar.xz &lt;span class="s2"&gt;"https://nodejs.org/dist/v26.13.0/node-v26.13.0-linux-x64.tar.xz"&lt;/span&gt;
tar -xf node26.tar.xz
&lt;span class="nv"&gt;NODE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;./node-v26.13.0-linux-x64/bin/node
&lt;span class="nv"&gt;$NODE&lt;/span&gt; --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The warm/cold benchmark, trimmed to the essentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;N&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5_000_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;KEYS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;compute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;timeIt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hrtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;bigint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hrtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;bigint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1e6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;oldWarm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;compute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="no"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;compute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;newWarm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;compute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getOrInsertComputed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="no"&gt;KEYS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;compute&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'old:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;timeIt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oldWarm&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'ms'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'new:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;timeIt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newWarm&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'ms'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$NODE&lt;/span&gt; bench.mjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every command and snippet above ran on the same machine the numbers came from, including the download.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do with this
&lt;/h2&gt;

&lt;p&gt;The one place I'd actually swap in &lt;code&gt;getOrInsertComputed&lt;/code&gt; today is the in-flight promise map people already hand-roll around a shared fetch or a shared database lookup. That code usually has its own bugs — a missing &lt;code&gt;.finally()&lt;/code&gt;, a key that never gets cleaned up — and this replaces it with something shorter and more obviously correct for the success path. It won't be more obviously correct for the failure path, though. I'd still add &lt;code&gt;.catch(() =&amp;gt; cache.delete(key))&lt;/code&gt; around it myself, because this method's name gives you no hint that a single rejection sits there forever otherwise.&lt;/p&gt;

&lt;p&gt;I would not swap it in anywhere I cared about raw throughput. A hot cache lookup that currently reads &lt;code&gt;map.get(key) ?? compute-and-set&lt;/code&gt; is doing less work than &lt;code&gt;getOrInsertComputed&lt;/code&gt; does on this V8 build, not more, and the benchmark above says so plainly. Leave it alone.&lt;/p&gt;

&lt;p&gt;And if a teammate reaches for &lt;code&gt;getOrInsert&lt;/code&gt; with anything other than a hardcoded constant as the second argument, that's worth a second look in review. The name reads as the lazy, safe default. It isn't; &lt;code&gt;getOrInsertComputed&lt;/code&gt; is the one that's lazy, and the two are close enough in spelling that autocomplete will happily suggest the wrong one at 2am.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>performance</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Traefik 3.8's tap middleware triples request latency even with an instant local receiver</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Mon, 09 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/traefik-38s-tap-middleware-triples-request-latency-even-with-an-instant-local-receiver-421a</link>
      <guid>https://dev.to/alexgeorgiev17/traefik-38s-tap-middleware-triples-request-latency-even-with-an-instant-local-receiver-421a</guid>
      <description>&lt;p&gt;Traefik 3.8.0-rc.1 shipped on 30 October with a middleware called &lt;code&gt;tap&lt;/code&gt;. It copies every request and response passing through a router and posts each one, as a JSON record, to a Traefik service of your choosing. It is meant for audit logging or compliance trails without rewiring your application.&lt;/p&gt;

&lt;p&gt;The documentation is upfront about the cost: "the time taken by the tap service adds to the latency of every request," because the record is sent inline rather than in the background. I wanted to know how much that actually costs, whether it is really strictly additive as worded, and what happens when the tap endpoint is slow, unreachable, or fed more than it can handle.&lt;/p&gt;

&lt;p&gt;This is a release candidate, not a stable release, so none of this is final. But the behaviour is unlikely to change much before 3.8.0 ships, since it is documented as intentional.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;I ran Traefik 3.8.0-rc.1 in Docker, routing to &lt;code&gt;traefik/whoami&lt;/code&gt; (a trivial Go binary that echoes the request back, chosen so the backend itself adds almost no latency of its own) and a small Python &lt;code&gt;http.server&lt;/code&gt; standing in for the tap receiver, all on one Docker bridge network so there was no real network hop to account for.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;middlewares&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;tap-fast&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;tap&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tapsvc&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/req&lt;/span&gt;
          &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;5s&lt;/span&gt;
        &lt;span class="na"&gt;response&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tapsvc&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/resp&lt;/span&gt;
          &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;5s&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Baseline latency, no tap, 100 sequential requests, three runs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;run&lt;/th&gt;
&lt;th&gt;mean&lt;/th&gt;
&lt;th&gt;p50&lt;/th&gt;
&lt;th&gt;p95&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.88ms&lt;/td&gt;
&lt;td&gt;0.87ms&lt;/td&gt;
&lt;td&gt;1.05ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1.09ms&lt;/td&gt;
&lt;td&gt;1.08ms&lt;/td&gt;
&lt;td&gt;1.48ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;0.94ms&lt;/td&gt;
&lt;td&gt;0.85ms&lt;/td&gt;
&lt;td&gt;1.01ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With the &lt;code&gt;tap&lt;/code&gt; middleware attached, pointed at the same receiver on the same host, answering instantly:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;run&lt;/th&gt;
&lt;th&gt;mean&lt;/th&gt;
&lt;th&gt;p50&lt;/th&gt;
&lt;th&gt;p95&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2.49ms&lt;/td&gt;
&lt;td&gt;2.37ms&lt;/td&gt;
&lt;td&gt;3.34ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;2.68ms&lt;/td&gt;
&lt;td&gt;2.58ms&lt;/td&gt;
&lt;td&gt;3.34ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2.67ms&lt;/td&gt;
&lt;td&gt;2.58ms&lt;/td&gt;
&lt;td&gt;3.17ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That is roughly triple the baseline mean, and the gap holds steady across all three runs. This is the best case: receiver on the same Docker network, no payload, no slowdown of its own. There is no way to get a better number out of this middleware than the one above.&lt;/p&gt;

&lt;h2&gt;
  
  
  The documented claim holds, almost exactly
&lt;/h2&gt;

&lt;p&gt;The quoted sentence from the docs is a specific, checkable claim: the tap service's own latency becomes part of the request's latency. I set the receiver to sleep before responding and reran the same benchmark.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;receiver delay&lt;/th&gt;
&lt;th&gt;tapped request latency (mean)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0ms&lt;/td&gt;
&lt;td&gt;2.6ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10ms&lt;/td&gt;
&lt;td&gt;23.3ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;50ms&lt;/td&gt;
&lt;td&gt;104.9ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A 10ms receiver delay added about 20ms, not 10. A 50ms delay added about 100ms, not 50. That is because &lt;code&gt;tap&lt;/code&gt; records the request and the response separately, each a synchronous call, so a slow receiver gets charged twice per client request. The documentation doesn't spell out the factor of two; I only found it by varying the delay and checking the arithmetic.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses: an unreachable tap service becomes an outage
&lt;/h2&gt;

&lt;p&gt;I killed the receiver (dropped the TCP connection instead of answering) and hit a route configured with &lt;code&gt;rejectOnRecordError: true&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;500&lt;/span&gt; &lt;span class="ne"&gt;Internal Server Error&lt;/span&gt;
&lt;span class="na"&gt;Content-Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;text/plain; charset=utf-8&lt;/span&gt;

Internal Server Error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every real request behind that router now fails, with no detail beyond "Internal Server Error", until the audit endpoint comes back. That is the documented behaviour, and it is a serious thing to turn on for a production router without a highly available tap endpoint behind it.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;rejectOnRecordError: false&lt;/code&gt; against the same dead receiver, the real request still returned 200 normally. Traefik logged the failure instead of surfacing it to the client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERR Unable to send the request record  error="tap service returned 502" middlewareName=tap-noreject@file middlewareType=Tap
ERR Unable to send the response record error="tap service returned 502" middlewareName=tap-noreject@file middlewareType=Tap
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the line to alert on in production: &lt;code&gt;middlewareType=Tap&lt;/code&gt; plus &lt;code&gt;Unable to send the&lt;/code&gt;. There's no counter or metric for it that I could find in this release candidate, only the log line, so anyone deploying &lt;code&gt;tap&lt;/code&gt; with &lt;code&gt;rejectOnRecordError: false&lt;/code&gt; needs log-based alerting or they will not notice their audit trail has silently stopped.&lt;/p&gt;

&lt;h2&gt;
  
  
  The documented size limit only limits what's recorded, not what's served
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;maxRecordBodySize&lt;/code&gt; caps how much of the body ends up in the JSON record, with the remainder marked &lt;code&gt;bodyTruncated: true&lt;/code&gt;. I sent a 200,001-byte POST body through a route with &lt;code&gt;maxRecordBodySize: 65536&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The record the tap service received held exactly 65,536 bytes of (base64-encoded) body and &lt;code&gt;"bodyTruncated":true&lt;/code&gt;. The request that actually reached &lt;code&gt;whoami&lt;/code&gt;, separately, carried the full 200,001 bytes, confirmed by the &lt;code&gt;Content-Length&lt;/code&gt; header whoami echoed back. The truncation setting is purely about the audit copy; it has no effect on the real request path, and does not act as a backdoor request size limit the way I half expected before testing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Under concurrency, the overhead doesn't stay fixed, it compounds
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;concurrent clients&lt;/th&gt;
&lt;th&gt;baseline mean&lt;/th&gt;
&lt;th&gt;baseline p95&lt;/th&gt;
&lt;th&gt;tapped mean&lt;/th&gt;
&lt;th&gt;tapped p95&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;6.94ms&lt;/td&gt;
&lt;td&gt;12.04ms&lt;/td&gt;
&lt;td&gt;13.12ms&lt;/td&gt;
&lt;td&gt;18.16ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;12.39ms&lt;/td&gt;
&lt;td&gt;24.28ms&lt;/td&gt;
&lt;td&gt;52.53ms&lt;/td&gt;
&lt;td&gt;68.39ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;14.92ms&lt;/td&gt;
&lt;td&gt;32.68ms&lt;/td&gt;
&lt;td&gt;101.22ms&lt;/td&gt;
&lt;td&gt;127.43ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At 10 concurrent clients, tap added about 1.9x to mean latency. At 100, it was closer to 6.8x. The untapped baseline also degrades under load, as any server does, but the tapped route degrades faster, because every request is now also opening and completing two extra HTTP exchanges to the tap service, and those compete for the same connection pool as everything else Traefik is doing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My first pass at the concurrency test showed something alarming: 50 concurrent clients against the tapped route produced a p95 of 1,844ms, nearly two seconds, against 23ms for the untapped baseline at the same concurrency. I was about to write that up as a serious scaling flaw in the RC.&lt;/p&gt;

&lt;p&gt;It wasn't one. My tap receiver was a bare &lt;code&gt;http.server.ThreadingHTTPServer&lt;/code&gt;, which inherits a default TCP accept backlog of 5 connections from &lt;code&gt;socketserver.BaseServer&lt;/code&gt;. Fifty concurrent client requests meant up to a hundred near-simultaneous connections landing on the receiver, and most of them queued at the kernel socket level before Python ever saw them. I was benchmarking my own test harness's accept queue, not Traefik.&lt;/p&gt;

&lt;p&gt;Setting &lt;code&gt;request_queue_size = 512&lt;/code&gt; on the receiver and rerunning produced the numbers in the table above, which are still a real and substantial slowdown, just not a nearly-2-second one. The lesson: when a reverse proxy with hundreds of real-world production users starts behaving two orders of magnitude worse than expected under a toy benchmark, the toy is the more likely suspect.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the timeout actually buys you
&lt;/h2&gt;

&lt;p&gt;The docs recommend keeping &lt;code&gt;timeout&lt;/code&gt; short, as a way to bound the damage from a slow tap service. I tested that directly: receiver delay set to 2 seconds, &lt;code&gt;timeout: 300ms&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;rejectOnRecordError: false&lt;/code&gt;, the request took 603ms and returned 200: the 300ms timeout fired for both the request-side and response-side record, back to back, and Traefik gave up on each and served the real response anyway. With &lt;code&gt;rejectOnRecordError: true&lt;/code&gt;, the request took 301ms and returned 500: Traefik didn't even wait for the response-side timeout once the request-side one had already failed.&lt;/p&gt;

&lt;p&gt;So the timeout does exactly what it claims: it caps the worst case at roughly &lt;code&gt;2 x timeout&lt;/code&gt; instead of however slow the tap service actually is. It does not get you to zero added latency, because both directions still wait out their own timeout before giving up.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs beyond latency
&lt;/h2&gt;

&lt;p&gt;A single &lt;code&gt;docker stats&lt;/code&gt; sample isn't a profile, so treat this as a rough sketch rather than a measurement: Traefik's CPU usage went from about 6.6% during a burst of 300 plain requests to about 22.7% during the same burst against the body-recording route with 60KB payloads. Memory stayed flat at roughly 35MB in both cases. The truncation and streaming design seems to mean tap doesn't hold large bodies in memory, but it clearly does more CPU work marshalling and shipping them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network create tapnet
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="nb"&gt;whoami&lt;/span&gt; &lt;span class="nt"&gt;--network&lt;/span&gt; tapnet traefik/whoami
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; tapreceiver &lt;span class="nt"&gt;--network&lt;/span&gt; tapnet &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;/tap_receiver.py:/app.py"&lt;/span&gt; python:3.12-slim python3 /app.py
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; traefik_tap &lt;span class="nt"&gt;--network&lt;/span&gt; tapnet &lt;span class="nt"&gt;-p&lt;/span&gt; 18080:80 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;/traefik.yml:/etc/traefik/traefik.yml"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;/dynamic.yml:/etc/traefik/dynamic.yml"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  traefik:v3.8.0-rc.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A minimal tap receiver, standard library only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# tap_receiver.py
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;http.server&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BaseHTTPRequestHandler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ThreadingHTTPServer&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseHTTPRequestHandler&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;do_POST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Content-Length&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rfile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end_headers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ThreadingHTTPServer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;request_queue_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt;  &lt;span class="c1"&gt;# the default of 5 will give you fake numbers
&lt;/span&gt;
&lt;span class="nc"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0.0.0.0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;Handler&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;serve_forever&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The router and middleware, as a &lt;code&gt;dynamic.yml&lt;/code&gt; for Traefik's file provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;routers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;tapped&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;rule&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PathPrefix(`/tapped`)"&lt;/span&gt;
      &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;whoami&lt;/span&gt;
      &lt;span class="na"&gt;middlewares&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tap-fast"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;whoami&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;loadBalancer&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;servers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[{&lt;/span&gt;&lt;span class="nv"&gt;url&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;http://whoami:80"&lt;/span&gt;&lt;span class="pi"&gt;}]&lt;/span&gt;
    &lt;span class="na"&gt;tapsvc&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;loadBalancer&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;servers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[{&lt;/span&gt;&lt;span class="nv"&gt;url&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;http://tapreceiver:9000"&lt;/span&gt;&lt;span class="pi"&gt;}]&lt;/span&gt;
  &lt;span class="na"&gt;middlewares&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;tap-fast&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;tap&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;tapsvc&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;/req&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;5s&lt;/span&gt;&lt;span class="pi"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;response&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;tapsvc&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;/resp&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;5s&lt;/span&gt;&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then compare &lt;code&gt;curl -w '%{time_total}\n' -o /dev/null -s http://localhost:18080/plain&lt;/code&gt; against the same call on &lt;code&gt;/tapped&lt;/code&gt;, repeated a few dozen times.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do with this
&lt;/h2&gt;

&lt;p&gt;If you're weighing &lt;code&gt;tap&lt;/code&gt; for audit logging on a route that matters, don't put it on a path where tail latency is the thing you get paged for, at least not in this release candidate, and not with &lt;code&gt;rejectOnRecordError: true&lt;/code&gt; unless your tap endpoint is more available than the service you're protecting it for. Keep &lt;code&gt;timeout&lt;/code&gt; low regardless of which way &lt;code&gt;rejectOnRecordError&lt;/code&gt; is set, since it's the only knob that bounds the worst case. And if you do turn it on, set up log-based alerting on &lt;code&gt;middlewareType=Tap&lt;/code&gt; errors now, because a silently dead audit trail is the kind of thing nobody notices until someone asks for logs that were never written.&lt;/p&gt;

</description>
      <category>traefik</category>
      <category>docker</category>
      <category>devops</category>
      <category>performance</category>
    </item>
    <item>
      <title>Redis 8.12-rc1's roaring bitmap type shrinks a sparse bitmap from 24MB to 239KB</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Sun, 08 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/redis-812-rc1s-roaring-bitmap-type-shrinks-a-sparse-bitmap-from-24mb-to-239kb-5bll</link>
      <guid>https://dev.to/alexgeorgiev17/redis-812-rc1s-roaring-bitmap-type-shrinks-a-sparse-bitmap-from-24mb-to-239kb-5bll</guid>
      <description>&lt;p&gt;Redis 8.12-rc1 folds a side project called redis-roaring into core. It gives bitmaps a second, opt-in internal representation based on Roaring Bitmaps, and a new command, &lt;code&gt;BITRANGEINTARRAY&lt;/code&gt;, that reads the set-bit positions straight out of it. The release notes describe this as lowering memory use and speeding up bitmap operations. I wanted to know what that actually means for a bitmap that looks like something I'd really store, not a synthetic all-ones or all-zeros string.&lt;/p&gt;

&lt;p&gt;There's no official Docker image for 8.12-rc1 yet, so I built it from the tagged source inside a throwaway container (the commands are in "Run it yourself" below). &lt;code&gt;redis-cli INFO server&lt;/code&gt; reports this build as &lt;code&gt;redis_version:8.11.240&lt;/code&gt;, not 8.12 anything — the pre-release versioning is a full point behind the tag name, which would trip up any script checking the version string before relying on this feature.&lt;/p&gt;

&lt;p&gt;The headline number first, then the three things that make it less simple than it sounds.&lt;/p&gt;

&lt;h2&gt;
  
  
  The sparse case
&lt;/h2&gt;

&lt;p&gt;I set 20,000 bits at pseudo-random offsets across a 200,000,000-bit range — a rough stand-in for "which of 200 million user IDs did something today, and about 20,000 of them did." I built the same bitmap twice, once with the new &lt;code&gt;bitmap-default-roaring&lt;/code&gt; config off (the default) and once with it on, using the same seeded random sequence both times so the two bitmaps mark identical bits.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;legacy bitmap&lt;/th&gt;
&lt;th&gt;roaring bitmap&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MEMORY USAGE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;25,165,860 bytes&lt;/td&gt;
&lt;td&gt;244,837 bytes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ratio&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;103x smaller&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;BITCOUNT&lt;/code&gt; throughput (3 runs)&lt;/td&gt;
&lt;td&gt;1,040–1,056 req/s&lt;/td&gt;
&lt;td&gt;14,706–15,152 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;OBJECT ENCODING&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;raw&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;bitmap-roaring&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The memory drop is the one I expected from "roaring bitmap," since that's exactly the data structure's reason to exist: it stores runs and small arrays of set positions instead of one bit per possible value. What I didn't expect going in was that &lt;code&gt;BITCOUNT&lt;/code&gt; — a full scan of the bitmap under the old encoding — got roughly 14 times faster too, because counting set bits in a roaring structure means walking a much smaller set of containers instead of every byte.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;BITCOUNT&lt;/code&gt; numbers came from &lt;code&gt;redis-benchmark -n 5000 -c 1 BITCOUNT &amp;lt;key&amp;gt;&lt;/code&gt;, three runs each, reported as the full range I saw across those runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The dense case, which argues the other way
&lt;/h2&gt;

&lt;p&gt;Roaring bitmaps compress well when bits are either clustered into runs or sparse enough to list individually. They do not compress a bitmap where roughly half the bits are set with no pattern, because there's nothing to run-length or array-encode. I built a 1,000,000-bit bitmap with every even bit set — deliberately dense, deliberately patterned so run-length encoding gets a fair shot — and it still came out bigger under roaring:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;legacy bitmap&lt;/th&gt;
&lt;th&gt;roaring bitmap&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MEMORY USAGE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;131,103 bytes&lt;/td&gt;
&lt;td&gt;132,376 bytes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ratio&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;~1% larger&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A 1% regression isn't going to hurt anyone, but it inverts the headline cleanly: the "smaller and faster" release-notes framing holds for the sparse, real-world-shaped case and not for a bitmap that's already dense. &lt;code&gt;BITCOUNT&lt;/code&gt; on this dense pair came out close to identical too (23,622–25,000 req/s legacy against 26,087–27,778 req/s roaring) — not nothing, but nowhere near the 14x on the sparse bitmap, because at 125KB the legacy scan was already fast enough that there wasn't much left to win.&lt;/p&gt;

&lt;h2&gt;
  
  
  It's not a string encoding, it's a different type
&lt;/h2&gt;

&lt;p&gt;This is the part I'd have gotten wrong by assumption. A roaring bitmap is not a new &lt;code&gt;OBJECT ENCODING&lt;/code&gt; of the &lt;code&gt;string&lt;/code&gt; type the way &lt;code&gt;intset&lt;/code&gt; or &lt;code&gt;listpack&lt;/code&gt; are encodings of other types. &lt;code&gt;TYPE&lt;/code&gt; on a roaring key returns &lt;code&gt;bitmap&lt;/code&gt;, not &lt;code&gt;string&lt;/code&gt;, and Redis enforces that split:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli GETRANGE dense_roaring 0 10
&lt;span class="go"&gt;WRONGTYPE Operation against a key holding the wrong kind of value
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli APPEND dense_roaring &lt;span class="s2"&gt;"x"&lt;/span&gt;
&lt;span class="go"&gt;WRONGTYPE Operation against a key holding the wrong kind of value
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli SETRANGE dense_roaring 0 &lt;span class="s2"&gt;"x"&lt;/span&gt;
&lt;span class="go"&gt;WRONGTYPE Operation against a key holding the wrong kind of value
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any command that treats the value as a byte string — &lt;code&gt;GETRANGE&lt;/code&gt;, &lt;code&gt;APPEND&lt;/code&gt;, &lt;code&gt;SETRANGE&lt;/code&gt;, &lt;code&gt;STRLEN&lt;/code&gt; — refuses outright. The bit-oriented commands don't care:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli GETBIT dense_roaring 0
&lt;span class="go"&gt;(integer) 1
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli BITCOUNT dense_roaring
&lt;span class="go"&gt;(integer) 500000
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli BITFIELD dense_roaring GET u8 0
&lt;span class="go"&gt;(integer) 170
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli BITOP AND destkey dense_roaring dense_legacy
&lt;span class="go"&gt;(integer) 125000
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That last one mixes a roaring key and a legacy string-backed bitmap in the same &lt;code&gt;BITOP&lt;/code&gt; and it just works. So the practical rule is: anything in the bitmap command family is fine across both representations, anything in the string command family now refuses on a roaring key where it used to succeed. If you have code that does &lt;code&gt;GETRANGE&lt;/code&gt; on a key you also &lt;code&gt;SETBIT&lt;/code&gt; into — which is a real pattern for packing flags into a string you also read back in chunks — turning on &lt;code&gt;bitmap-default-roaring&lt;/code&gt; will break it, silently, the first time Redis picks the new encoding for a fresh key.&lt;/p&gt;

&lt;h2&gt;
  
  
  The config only affects new keys
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;bitmap-default-roaring&lt;/code&gt; reads like a global switch, and in one sense it is: flip it and every subsequent &lt;code&gt;SETBIT&lt;/code&gt; on a key that doesn't exist yet creates a roaring bitmap instead of a string. What it doesn't do is touch anything that already exists. I set a bit on a fresh key with the config on, got &lt;code&gt;bitmap-roaring&lt;/code&gt; back from &lt;code&gt;OBJECT ENCODING&lt;/code&gt;, then turned the config off and set another bit on that same key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli CONFIG SET bitmap-default-roaring no
&lt;span class="go"&gt;OK
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli SETBIT dense_roaring 1000001 1
&lt;span class="go"&gt;(integer) 0
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli OBJECT ENCODING dense_roaring
&lt;span class="go"&gt;"bitmap-roaring"
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Still roaring. The config is read once, at key creation, and never again for that key. There's no in-place conversion command either way, as far as I could find — if you want to move an existing bitmap between representations you'd have to read it out and rebuild it under the other setting.&lt;/p&gt;

&lt;h2&gt;
  
  
  BITRANGEINTARRAY works on anything, and never errors
&lt;/h2&gt;

&lt;p&gt;I'd assumed &lt;code&gt;BITRANGEINTARRAY&lt;/code&gt; — which returns the offsets of set bits in a range, instead of making the caller walk &lt;code&gt;BITPOS&lt;/code&gt; one position at a time — was exclusive to the new type, since the release notes introduce it in the same breath as roaring bitmaps. It isn't. It runs on a plain legacy bitmap, and on a key that was never meant to be a bitmap at all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli SET not_a_bitmap &lt;span class="s2"&gt;"hello"&lt;/span&gt;
&lt;span class="go"&gt;OK
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli BITRANGEINTARRAY not_a_bitmap 0 10
&lt;span class="go"&gt;1
2
4
9
10
13
15
&lt;/span&gt;&lt;span class="c"&gt;...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those are just the set bits in the ASCII encoding of "hello," which is consistent with how every other Redis bit command already treats a plain string. I also fed it a battery of bad ranges — a nonexistent key, &lt;code&gt;end&lt;/code&gt; before &lt;code&gt;start&lt;/code&gt;, a negative start, a negative end, an end several orders of magnitude past the bitmap's length — and none of it errored:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli BITRANGEINTARRAY nonexistent_key 0 10
&lt;span class="go"&gt;(empty array)
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli BITRANGEINTARRAY big_sparse_roaring 10 0
&lt;span class="go"&gt;(empty array)
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli BITRANGEINTARRAY big_sparse_roaring 0 &lt;span class="nt"&gt;-1&lt;/span&gt;
&lt;span class="go"&gt;(19998 results)
&lt;/span&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;redis-cli BITRANGEINTARRAY big_sparse_roaring 0 1000000000000
&lt;span class="go"&gt;(19998 results)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A negative &lt;code&gt;end&lt;/code&gt; behaves like it does in &lt;code&gt;GETRANGE&lt;/code&gt; — "to the end of the bitmap" — rather than erroring, and an absurdly large &lt;code&gt;end&lt;/code&gt; just gets clamped. That's a reasonable design, but it means a bug in your own range arithmetic (an off-by-one that sends a negative number where you meant a small positive one) will not announce itself. It will just quietly return more or fewer bits than you meant to ask for.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a single bit costs, with and without roaring
&lt;/h2&gt;

&lt;p&gt;The 14x &lt;code&gt;BITCOUNT&lt;/code&gt; win is real, but it's a win for a command that touches the whole bitmap. I wanted to know whether a single &lt;code&gt;SETBIT&lt;/code&gt; on an existing key pays any kind of tax for being stored as a roaring container instead of a flat byte string. Repeated &lt;code&gt;SETBIT&lt;/code&gt; on the same existing bit, one connection:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;legacy&lt;/th&gt;
&lt;th&gt;roaring&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;throughput (3 runs)&lt;/td&gt;
&lt;td&gt;15,789–27,778 req/s&lt;/td&gt;
&lt;td&gt;27,273–28,571 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;And the same thing with 50 concurrent clients hammering the same key:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;legacy&lt;/th&gt;
&lt;th&gt;roaring&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;throughput (3 runs)&lt;/td&gt;
&lt;td&gt;112,360–131,579 req/s&lt;/td&gt;
&lt;td&gt;117,647–149,254 req/s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both ranges overlap enough that I don't think there's a real difference here, in either direction, at one connection or fifty. &lt;code&gt;BITPOS&lt;/code&gt; searching from offset 0 came out the same way — 23,622–27,273 req/s legacy against 25,000–29,126 req/s roaring. The speedup from roaring bitmaps is specific to operations that have to look at a large span of the bitmap at once. A point write or an early-exit search doesn't have much span to save on, so it doesn't get much faster, which is a narrower claim than "speeds up bitmap operations" taken at face value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watching it in production
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;INFO everything&lt;/code&gt; carries a new keysizes section that separates bitmap-shaped keys from plain strings, bucketed by size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="c"&gt;# Keysizes
&lt;/span&gt;&lt;span class="n"&gt;db0_distrib_strings_sizes&lt;/span&gt;:&lt;span class="m"&gt;64&lt;/span&gt;&lt;span class="n"&gt;K&lt;/span&gt;=&lt;span class="m"&gt;1&lt;/span&gt;,&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt;=&lt;span class="m"&gt;1&lt;/span&gt;,&lt;span class="m"&gt;16&lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt;=&lt;span class="m"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;db0_distrib_bitmaps_sizes&lt;/span&gt;:&lt;span class="m"&gt;64&lt;/span&gt;&lt;span class="n"&gt;K&lt;/span&gt;=&lt;span class="m"&gt;2&lt;/span&gt;,&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt;=&lt;span class="m"&gt;1&lt;/span&gt;,&lt;span class="m"&gt;16&lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt;=&lt;span class="m"&gt;4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's useful on its own, independent of roaring: it's a live count of how many of your keys are bitmaps and how big they are, without having to sample keys with &lt;code&gt;MEMORY USAGE&lt;/code&gt; yourself. It doesn't currently split roaring bitmaps out from legacy ones in this view, so it tells you "how many big bitmaps do I have" but not "how many of them are roaring" — you'd still need &lt;code&gt;OBJECT ENCODING&lt;/code&gt; per key for that.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My first attempt at timing &lt;code&gt;BITCOUNT&lt;/code&gt; used a Lua script that called &lt;code&gt;redis.call('TIME')&lt;/code&gt; before and after a loop of 2,000 &lt;code&gt;BITCOUNT&lt;/code&gt; calls, on the theory that running the loop server-side would avoid the process-spawn overhead of shelling out to &lt;code&gt;redis-cli&lt;/code&gt; thousands of times. The two &lt;code&gt;TIME&lt;/code&gt; calls returned exactly the same microsecond value, every run, regardless of how much work happened between them.&lt;/p&gt;

&lt;p&gt;Redis scripts run with a frozen clock on purpose — a script has to produce the same result if it's replayed on a replica, so time-dependent commands inside &lt;code&gt;EVAL&lt;/code&gt; return a value fixed at script start, not the real clock. I'd read about this behaviour before and genuinely forgot it applied here, so I got a result that looked like "the loop took zero time" and sat with it for a few minutes before realising the instrumentation, not the server, was what had frozen. &lt;code&gt;redis-benchmark&lt;/code&gt;, which measures real round trips over the wire rather than asking the script to time itself, doesn't have this problem, which is what the numbers above actually come from.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;

&lt;p&gt;This needs Docker and a clone of Redis's own tree, since there's no published image for a release candidate yet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &lt;span class="nt"&gt;--depth&lt;/span&gt; 1 &lt;span class="nt"&gt;--branch&lt;/span&gt; 8.12-rc1 https://github.com/redis/redis.git redis-src
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Dockerfile.redis812 &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;'
FROM debian:bookworm-slim AS build
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y --no-install-recommends &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="sh"&gt;
    build-essential tcl libssl-dev pkg-config &amp;amp;&amp;amp; rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY redis-src/ .
RUN make -j4 BUILD_TLS=no

FROM debian:bookworm-slim
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y --no-install-recommends libssl3 &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="sh"&gt;
    &amp;amp;&amp;amp; rm -rf /var/lib/apt/lists/*
COPY --from=build /src/src/redis-server /usr/local/bin/redis-server
COPY --from=build /src/src/redis-cli /usr/local/bin/redis-cli
COPY --from=build /src/src/redis-benchmark /usr/local/bin/redis-benchmark
CMD ["redis-server", "--protected-mode", "no"]
&lt;/span&gt;&lt;span class="no"&gt;EOF
&lt;/span&gt;docker build &lt;span class="nt"&gt;-f&lt;/span&gt; Dockerfile.redis812 &lt;span class="nt"&gt;-t&lt;/span&gt; redis-812rc1 &lt;span class="nb"&gt;.&lt;/span&gt;
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; r812 &lt;span class="nt"&gt;-p&lt;/span&gt; 16379:6379 redis-812rc1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the sparse-versus-dense comparison itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# sparse: 20,000 bits in a 200,000,000-bit range&lt;/span&gt;
docker &lt;span class="nb"&gt;exec &lt;/span&gt;r812 redis-cli CONFIG SET bitmap-default-roaring no
docker &lt;span class="nb"&gt;exec &lt;/span&gt;r812 redis-cli EVAL &lt;span class="s2"&gt;"
  math.randomseed(42)
  for i=1,20000 do redis.call('SETBIT', KEYS[1], math.random(0,199999999), 1) end
  return redis.call('BITCOUNT', KEYS[1])"&lt;/span&gt; 1 sparse_legacy
docker &lt;span class="nb"&gt;exec &lt;/span&gt;r812 redis-cli MEMORY USAGE sparse_legacy

docker &lt;span class="nb"&gt;exec &lt;/span&gt;r812 redis-cli CONFIG SET bitmap-default-roaring &lt;span class="nb"&gt;yes
&lt;/span&gt;docker &lt;span class="nb"&gt;exec &lt;/span&gt;r812 redis-cli EVAL &lt;span class="s2"&gt;"
  math.randomseed(42)
  for i=1,20000 do redis.call('SETBIT', KEYS[1], math.random(0,199999999), 1) end
  return redis.call('BITCOUNT', KEYS[1])"&lt;/span&gt; 1 sparse_roaring
docker &lt;span class="nb"&gt;exec &lt;/span&gt;r812 redis-cli MEMORY USAGE sparse_roaring

&lt;span class="c"&gt;# throughput comparison&lt;/span&gt;
docker &lt;span class="nb"&gt;exec &lt;/span&gt;r812 redis-benchmark &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 5000 &lt;span class="nt"&gt;-c&lt;/span&gt; 1 BITCOUNT sparse_legacy
docker &lt;span class="nb"&gt;exec &lt;/span&gt;r812 redis-benchmark &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 5000 &lt;span class="nt"&gt;-c&lt;/span&gt; 1 BITCOUNT sparse_roaring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On my machine that prints 25,170,660-ish bytes for the legacy key and 244,837 for the roaring one, and the same gap in &lt;code&gt;BITCOUNT&lt;/code&gt; throughput shown above.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do with this
&lt;/h2&gt;

&lt;p&gt;If you've got a sparse bitmap today — activity flags over a large ID space, a bloom-filter-adjacent membership check, anything where most bits are zero — &lt;code&gt;bitmap-default-roaring&lt;/code&gt; is worth testing against your own data once 8.12 reaches a stable release, with the understanding that it's a type change, not a free encoding swap. Audit for &lt;code&gt;GETRANGE&lt;/code&gt;, &lt;code&gt;APPEND&lt;/code&gt;, &lt;code&gt;SETRANGE&lt;/code&gt; or &lt;code&gt;STRLEN&lt;/code&gt; on any key you also &lt;code&gt;SETBIT&lt;/code&gt; into, because those will start failing the moment that key happens to land on the new encoding. And if your bitmaps are already dense, don't turn it on by default and assume it helps; measure your own shape, because mine got slightly worse.&lt;/p&gt;

</description>
      <category>redis</category>
      <category>database</category>
      <category>performance</category>
      <category>devops</category>
    </item>
    <item>
      <title>Containerd 2.4's switch to klauspost's gzip decoder speeds up real image layers by 18%</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Sat, 07 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/containerd-24s-switch-to-klausposts-gzip-decoder-speeds-up-real-image-layers-by-18-2jne</link>
      <guid>https://dev.to/alexgeorgiev17/containerd-24s-switch-to-klausposts-gzip-decoder-speeds-up-real-image-layers-by-18-2jne</guid>
      <description>&lt;p&gt;Containerd 2.4.0 shipped a one-line-sounding change: layer decompression now uses &lt;code&gt;klauspost/compress/gzip&lt;/code&gt; instead of the standard library's &lt;code&gt;compress/gzip&lt;/code&gt;. The pull request claimed 1.4 to 1.5 times faster decompression, measured on a 3.4GiB CUDA image and a 7GiB PyTorch image, on arm64. I run neither of those images, and my container host is an Intel Xeon, not an Apple Silicon or Graviton box, so I wanted to know what this actually buys an ordinary &lt;code&gt;python:3.12&lt;/code&gt; pull on ordinary x86_64 hardware.&lt;/p&gt;

&lt;p&gt;It buys about 18%, not 40-50%. The allocation story, on the other hand, held up completely.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually changed
&lt;/h2&gt;

&lt;p&gt;The change is PR #13560 against &lt;code&gt;containerd/containerd&lt;/code&gt;, merged 30 June 2026 and released in containerd 2.4.0 (16 September 2026). It touches exactly one function, &lt;code&gt;gzipDecompress&lt;/code&gt; in &lt;code&gt;pkg/archive/compression/compression.go&lt;/code&gt;, and only the decoder. Compression still goes through the standard library. The PR description is explicit that this "affects only gzip layer decompression" — nothing about zstd layers changes, because containerd was already using &lt;code&gt;klauspost/compress&lt;/code&gt; for those.&lt;/p&gt;

&lt;p&gt;My environment runs this code today. Docker Engine here bundles containerd v2.4.2, and &lt;code&gt;strings /usr/bin/containerd | grep klauspost/compress/gzip&lt;/code&gt; finds the vendored package compiled into the binary I actually have running.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting real layers to test against
&lt;/h2&gt;

&lt;p&gt;Benchmarking synthetic data would have missed the point — gzip's throughput depends heavily on what you feed it, and a container image layer is mostly binaries, shared libraries, and Python wheels, not random bytes or highly repetitive text. I pulled &lt;code&gt;python:3.12&lt;/code&gt; with &lt;code&gt;docker pull&lt;/code&gt;, which populates containerd's own content-addressable store, then read the real compressed layer blobs straight out of that store:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ctr &lt;span class="nt"&gt;-n&lt;/span&gt; moby content get sha256:&amp;lt;layer-digest&amp;gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; layer.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That gave me the amd64 manifest's seven layers, 392.8MiB compressed, 1081.3MiB decompressed once I ran them through &lt;code&gt;gzip -t&lt;/code&gt; to confirm they were intact. The smallest is a 249-byte metadata layer; the largest is 237MB compressed, 670MB decompressed.&lt;/p&gt;

&lt;p&gt;I wrote a small Go program that decompresses each blob with &lt;code&gt;compress/gzip&lt;/code&gt; and with &lt;code&gt;github.com/klauspost/compress/gzip&lt;/code&gt; in turn, three times each, keeping the fastest run, and reading &lt;code&gt;runtime.MemStats&lt;/code&gt; around the final run to get allocation counts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The headline number, and the one that argues against it
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;stdlib &lt;code&gt;compress/gzip&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;&lt;code&gt;klauspost/compress/gzip&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Total time (7 layers, 1081.3MiB)&lt;/td&gt;
&lt;td&gt;5.85s&lt;/td&gt;
&lt;td&gt;4.98s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Throughput&lt;/td&gt;
&lt;td&gt;184.8 MiB/s&lt;/td&gt;
&lt;td&gt;217.3 MiB/s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Speedup&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;1.18x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Per layer, the speedup ranged from 1.12x to 1.23x, with the 249-byte layer too small to measure meaningfully either way. That's a real, repeatable improvement — I ran the full suite twice on separate invocations and got 1.18x and 1.19x — but it is well under half of what the PR's own numbers suggested.&lt;/p&gt;

&lt;p&gt;I don't think the PR's authors were wrong; I think the gap is the workload. Their test images were dominated by large, highly compressible binary blobs typical of CUDA and PyTorch wheels, run on Apple Silicon or Graviton cores with different memory and cache characteristics than my Xeon. A &lt;code&gt;python:3.12&lt;/code&gt; base image is a more ordinary mix of shared libraries, &lt;code&gt;.pyc&lt;/code&gt; files, and documentation, and on this specific box the win is real but modest. If your images look more like a typical web service than a GPU training image, expect something closer to my number than theirs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The allocation claim held up exactly
&lt;/h2&gt;

&lt;p&gt;The PR's second claim was about memory pressure, not speed, and this one matched almost precisely on the largest layer in my set:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;stdlib&lt;/th&gt;
&lt;th&gt;klauspost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Mallocs (237MB compressed layer)&lt;/td&gt;
&lt;td&gt;425,133&lt;/td&gt;
&lt;td&gt;1,246&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bytes allocated&lt;/td&gt;
&lt;td&gt;66.6 MiB&lt;/td&gt;
&lt;td&gt;0.15 MiB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That's 341 times fewer allocations and about 444 times less memory churned through the allocator, for decompressing the same bytes into the same output. The PR quoted similar ratios on its own test images (1.91 million mallocs down to 1,948, 305MiB down to 0.18MiB), and my numbers land in the same range even though the raw layer sizes don't match. This is the part of the change that's architecture- and workload-independent: fewer, larger buffer allocations instead of one small allocation per inflate call, regardless of what's inside the layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Under concurrency, the gap didn't widen the way I expected
&lt;/h2&gt;

&lt;p&gt;Containerd unpacks the layers of a pulled image in parallel, so I decompressed all seven layers from four goroutines worth of CPU at once, three times, keeping the best run:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;stdlib&lt;/th&gt;
&lt;th&gt;klauspost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Wall time, 7 layers concurrently&lt;/td&gt;
&lt;td&gt;3.485s&lt;/td&gt;
&lt;td&gt;3.007s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Speedup&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;1.16x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I expected concurrency to widen klauspost's advantage, on the theory that stdlib's heavier allocation rate would cause more garbage-collector pressure under parallel load, and that pressure would compound. It didn't: 1.16x concurrent against 1.18x serial, within noise of each other. On four cores, both versions are simply CPU-bound by the cost of running DEFLATE, and the allocator wasn't the bottleneck at this scale. The allocation win is real, but on this machine it didn't translate into an extra concurrency dividend.&lt;/p&gt;

&lt;h2&gt;
  
  
  A claim from the PR discussion I couldn't reproduce
&lt;/h2&gt;

&lt;p&gt;During review, a maintainer reported that a fuzzing job slowed from roughly 1.59 million executions per second to about 26,000 after this change, and the author attributed it to klauspost's reader allocating its buffers eagerly on construction, even when the fuzz harness never reads from it. I tested exactly that: calling &lt;code&gt;NewReader&lt;/code&gt; on a real 237MB layer and immediately closing it, 2,000 times, with no read in between.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stdlib     total=25ms per-call=12.719µs
klauspost  total=19ms per-call=9.598µs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Klauspost's reader was not slower to construct — it was marginally faster, on both runs I did. I think the fuzzer's reported 60x slowdown is specific to the fuzz harness's own execution pattern (likely many small or malformed inputs, triggering different code paths than a &lt;code&gt;NewReader&lt;/code&gt; call against a valid, cached file), not something that shows up on a plain construction-only benchmark against real data. I can't confirm the fuzzer's number was wrong; I can only confirm I didn't see anything like it under a more ordinary access pattern, and anyone deciding whether this matters for their own fuzzing setup should test their own harness rather than extrapolate from either of our numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses, and a surprise about when it refuses
&lt;/h2&gt;

&lt;p&gt;I corrupted a copy of the largest layer two ways: truncated to 50 bytes, truncated to 1MB, and with a single byte flipped at offset 5,000,000 in the full 237MB file. Both decoders gave identical errors on the same inputs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=== 50 bytes ===
stdlib:    err=unexpected EOF
klauspost: err=unexpected EOF

=== 1MB of 237MB ===
stdlib:    bytes=3757688 err=unexpected EOF
klauspost: bytes=3757688 err=unexpected EOF

=== full file, one byte flipped ===
stdlib:    bytes=669852201 err=gzip: invalid checksum
klauspost: bytes=669852201 err=gzip: invalid checksum
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last one is the interesting case. Flipping a single byte deep inside a 237MB compressed stream didn't produce an error at the point of corruption. Both decoders happily decompressed all 670MB of output — garbage from the flip point onward, but no error — and only failed at the very end, when the gzip trailer's CRC32 checksum didn't match what had actually come out. Neither library changed this behaviour; it's inherent to the gzip format, which checks integrity once, after the fact, rather than per block. If you're pulling a large layer over a flaky connection, this is the shape of failure to expect: you pay for decompressing the entire thing before being told it was corrupt, independent of which decoder unpacked it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My working assumption going in was that klauspost's allocation efficiency would show its biggest advantage exactly where allocation-heavy code usually suffers most: under concurrent load, where garbage collection has to compete with multiple goroutines doing real work. I built the concurrent test expecting to report a bigger number than the serial one. It came back smaller — 1.16x against 1.18x, a difference inside the run-to-run noise I was seeing anyway. Four cores running seven goroutines' worth of DEFLATE is simply CPU-bound on the arithmetic, and reducing allocator traffic that wasn't the bottleneck doesn't buy anything extra. I'd have reported this wrong if I'd gone in assuming the theory was obviously true and skipped actually running the concurrent case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;

&lt;p&gt;This needs Go 1.24+ and either Docker with a running daemon, or direct access to a containerd content store.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull python:3.12
&lt;span class="nv"&gt;SOCK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/var/run/docker/containerd/containerd.sock
&lt;span class="nb"&gt;mkdir &lt;/span&gt;layers
&lt;span class="c"&gt;# get the amd64 manifest digest from the image index, then for each layer:&lt;/span&gt;
ctr &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;$SOCK&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; moby content get sha256:&amp;lt;layer-digest&amp;gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; layers/&amp;lt;digest&amp;gt;.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;gzipbench &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;gzipbench
go mod init gzipbench
go get github.com/klauspost/compress@v1.18.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"io"&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;
    &lt;span class="s"&gt;"path/filepath"&lt;/span&gt;
    &lt;span class="s"&gt;"time"&lt;/span&gt;

    &lt;span class="n"&gt;stdgzip&lt;/span&gt; &lt;span class="s"&gt;"compress/gzip"&lt;/span&gt;
    &lt;span class="n"&gt;kgzip&lt;/span&gt; &lt;span class="s"&gt;"github.com/klauspost/compress/gzip"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;decompress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;open&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadCloser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;panic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Discard&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Since&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Glob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s"&gt;"*.tar.gz"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;decompress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadCloser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;stdgzip&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kp&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;decompress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Reader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadCloser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;kgzip&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%-20s std=%s klauspost=%s speedup=%.2fx&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Base&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kp&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go run &lt;span class="nb"&gt;.&lt;/span&gt; ../layers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran every command above as part of this post, on the same host and image as the numbers reported.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do with this
&lt;/h2&gt;

&lt;p&gt;If you're already on containerd 2.4.0 or later — check with &lt;code&gt;ctr --version&lt;/code&gt;, or &lt;code&gt;docker version --format '{{.Server.Components}}'&lt;/code&gt; if Docker bundles it — this change is already active and there is no flag to turn it on or off; the maintainers declined to add one. Don't expect it to move your &lt;code&gt;docker pull&lt;/code&gt; wall-clock time by much on an ordinary network connection, where transfer time usually dwarfs decompression time; it matters most when you're pulling from a fast local registry mirror or unpacking already-cached layers, where decompression is a bigger share of the total. And if you maintain anything that fuzzes gzip decoding against containerd's dependencies, check your own executions-per-second before assuming either my number or the one from the PR discussion applies to your harness.&lt;/p&gt;

</description>
      <category>containerd</category>
      <category>docker</category>
      <category>performance</category>
      <category>devops</category>
    </item>
    <item>
      <title>Prisma ORM 7's Rust-free query engine speeds up queries and slows down cold starts</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Fri, 06 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/prisma-orm-7s-rust-free-query-engine-speeds-up-queries-and-slows-down-cold-starts-1ac0</link>
      <guid>https://dev.to/alexgeorgiev17/prisma-orm-7s-rust-free-query-engine-speeds-up-queries-and-slows-down-cold-starts-1ac0</guid>
      <description>&lt;p&gt;Prisma's own blog says its new query engine is 85-90% smaller and up to four times faster. I installed it next to the engine it replaces and measured both claims on my own machine. The speed claim held up almost exactly. The size claim did not: &lt;code&gt;node_modules&lt;/code&gt; came out 31% bigger, not smaller.&lt;/p&gt;

&lt;p&gt;Prisma ORM removed its Rust query engine in version 7, released in November 2025, in favour of a TypeScript/WebAssembly "query compiler" that talks to your database through a JavaScript driver adapter instead of a native binary. It's the default now on 7.10.1, which shipped on 15 October 2026, so most people upgrading from Prisma 6 this year are about to hit this change whether they asked for it or not. I wanted to know what it actually costs and saves, not what the migration guide says it costs and saves.&lt;/p&gt;

&lt;p&gt;I built two identical projects, same two-model schema, same SQLite database, same seed data. One used &lt;code&gt;prisma@6.19.3&lt;/code&gt; with the classic &lt;code&gt;prisma-client-js&lt;/code&gt; generator and its Rust engine. The other used &lt;code&gt;prisma@7.10.1&lt;/code&gt; with the new &lt;code&gt;prisma-client&lt;/code&gt; generator, the &lt;code&gt;@prisma/adapter-better-sqlite3&lt;/code&gt; driver adapter, and a &lt;code&gt;prisma.config.ts&lt;/code&gt; file, because the old &lt;code&gt;url = "file:./dev.db"&lt;/code&gt; line in the datasource block is simply rejected now.&lt;/p&gt;

&lt;h2&gt;
  
  
  The number that matches the marketing
&lt;/h2&gt;

&lt;p&gt;I ran 2,000 sequential &lt;code&gt;findUnique&lt;/code&gt; calls against a table of 2,000 seeded users, three times each, after the connection was already warm.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Prisma 6 (Rust engine)&lt;/th&gt;
&lt;th&gt;Prisma 7.10.1 (Rust-free)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2,000 single-row lookups&lt;/td&gt;
&lt;td&gt;1,165 / 1,170 / 1,292 ms&lt;/td&gt;
&lt;td&gt;379 / 370 / 422 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Per lookup, average&lt;/td&gt;
&lt;td&gt;~0.60 ms&lt;/td&gt;
&lt;td&gt;~0.19 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That's a 3.1x speed-up, sitting right inside Prisma's own "three to four times faster" claim. I didn't expect a vendor number to hold up this cleanly, but for this specific shape of workload — a prepared single-row query run repeatedly on a warm connection — it did.&lt;/p&gt;

&lt;p&gt;Inserts told a different story. Seeding the same 2,000 rows one at a time took 4,957-7,436 ms on the old engine and 4,181-7,093 ms on the new one, which is the same number inside measurement noise. Neither engine is the bottleneck for sequential writes to a SQLite file with default journalling; the disk and the journal mode are. Prisma's speed claims are about reads, and testing only reads would have made the post look better than the change actually is.&lt;/p&gt;

&lt;h2&gt;
  
  
  The number that contradicts the marketing
&lt;/h2&gt;

&lt;p&gt;The 85-90% size reduction is framed around the query engine artifact itself: a 14 MB Rust binary against a 1.6 MB compiled TypeScript bundle. That comparison is real, but it isn't what lands in your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ du -sb node_modules    # prisma 6 project
266428327 node_modules   # 254.1 MiB

$ du -sb node_modules    # prisma 7.10.1 project
349344415 node_modules   # 333.3 MiB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;31% bigger, not 85-90% smaller. Some of that is the driver adapter and &lt;code&gt;better-sqlite3&lt;/code&gt;'s native bindings (27 MB), which Prisma 6 didn't need at all because the Rust engine spoke to SQLite directly. But most of it is that &lt;code&gt;@prisma/client&lt;/code&gt; still ships a WebAssembly query compiler for every supported database, in two size tiers, "fast" and "small":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -la node_modules/@prisma/client/runtime/query_compiler_*sqlite*
4406183  query_compiler_fast_bg.sqlite.wasm-base64.js
2214935  query_compiler_small_bg.sqlite.wasm-base64.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The old engine's SQLite WASM fallback was 2,895,111 bytes. The new "fast" compiler for the same database is 4.4 MB — bigger, not smaller. Only the "small" variant comes in under the old number, and only by about 24%. Multiply either one by five supported databases and the per-provider bloat adds up before you ever bundle your app. The &lt;code&gt;prisma&lt;/code&gt; CLI package has also grown: it now bundles &lt;code&gt;@prisma/studio-core&lt;/code&gt; and an embedded Postgres (&lt;code&gt;@electric-sql/pglite&lt;/code&gt;) for local development, which explains some of the extra weight but isn't something the size comparison on Prisma's blog post mentions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses
&lt;/h2&gt;

&lt;p&gt;Moving the connection string out of the schema file isn't a suggestion, it's enforced:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error: Prisma schema validation - (get-config wasm)
Error code: P1012
error: The datasource property `url` is no longer supported in schema files.
Move connection URLs for Migrate to `prisma.config.ts` and pass either
`adapter` for a direct database connection or `accelerateUrl` for
Accelerate to the `PrismaClient` constructor.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Construct the client with no adapter at all and you get a real error, not a crash buried three stack frames down:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PrismaClient was instantiated without any options. A driver adapter is
required to connect to your database.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the old middleware API is gone outright:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;$use&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;
&lt;span class="nx"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$use&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;not&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The documented replacement, a query extension via &lt;code&gt;$extends&lt;/code&gt;, does work as a drop-in. I wired up the exact pattern from Prisma's migration guide — intercepting &lt;code&gt;user.create&lt;/code&gt; to log the call before running it — and it fired correctly on the first try, which is more than I expected given how much else in this release needed a workaround of its own.&lt;/p&gt;

&lt;p&gt;One more packaging detail nobody warned me about: the generated client is TypeScript source, not compiled JavaScript. There's no &lt;code&gt;client.js&lt;/code&gt; to &lt;code&gt;require()&lt;/code&gt;. I had to run it with &lt;code&gt;node --experimental-strip-types&lt;/code&gt; or a bundler step; a project with no TypeScript build step of its own will not run this client as-is.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My first concurrency test looked like a second strike against the new engine. I fired 50 parallel &lt;code&gt;findUnique&lt;/code&gt; calls with &lt;code&gt;Promise.all&lt;/code&gt; and the new client took 14-17 ms against the old engine's 3.5-5 ms — three to four times slower, the opposite of the headline number, and I nearly wrote that up as "concurrency regression."&lt;/p&gt;

&lt;p&gt;Then I widened the test to 300 parallel calls over three trials instead of one batch of 50. The first trial on the new engine was slow, 56 ms. The second and third were 20.2 ms each — statistically identical to the old engine's 20.2-27 ms range on the same test. What I'd actually measured the first time was a one-off warm-up cost on the very first call of a given query shape through the WASM compiler, not a standing concurrency penalty. A single small batch with no repetition was the wrong instrument for the question I was asking.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs on cold start
&lt;/h2&gt;

&lt;p&gt;This is where the serverless pitch behind this whole rewrite runs into trouble. I split &lt;code&gt;require()&lt;/code&gt;, client construction, &lt;code&gt;$connect()&lt;/code&gt;, and the first query into separate timings, three runs each.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Stage&lt;/th&gt;
&lt;th&gt;Prisma 6&lt;/th&gt;
&lt;th&gt;Prisma 7.10.1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;require/import&lt;/td&gt;
&lt;td&gt;51-70 ms&lt;/td&gt;
&lt;td&gt;143-157 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;new PrismaClient()&lt;/td&gt;
&lt;td&gt;2-4 ms&lt;/td&gt;
&lt;td&gt;~2 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$connect()&lt;/td&gt;
&lt;td&gt;8.5-9 ms&lt;/td&gt;
&lt;td&gt;64-91 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;first query&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;7-11 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Total to first query&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~69 ms&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~236 ms&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The new client is about 3.4 times slower from process start to a usable connection, almost a mirror image of the 3.1x it gains back on repeated queries. Removing the Rust binary is specifically pitched as better for serverless and edge runtimes, where cold start is the metric that matters most, and on this measurement it's worse there, not better. A function that serves one request per invocation never gets to the warm, repeated-query phase where the new engine wins.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// bench.js — run once against each client, three times each&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dbFile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./prisma/dev.db&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hrtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bigint&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;$connect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;t1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hrtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bigint&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;connect_ms&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;t1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;t0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tQ0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hrtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bigint&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findUnique&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`u&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;@test.com`&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tQ1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hrtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bigint&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;query_ms_for&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tQ1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;tQ0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the Rust engine: &lt;code&gt;npm i prisma@6 @prisma/client@6&lt;/code&gt;, a plain &lt;code&gt;datasource db { provider = "sqlite" url = "file:./dev.db" }&lt;/code&gt;, then &lt;code&gt;node bench.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For the Rust-free engine: &lt;code&gt;npm i prisma@7.10.1 @prisma/client@7.10.1 @prisma/adapter-better-sqlite3@7.10.1 better-sqlite3&lt;/code&gt;, drop &lt;code&gt;url&lt;/code&gt; from the datasource block, add a &lt;code&gt;prisma.config.ts&lt;/code&gt;, generate with &lt;code&gt;provider = "prisma-client"&lt;/code&gt;, and run with &lt;code&gt;node --experimental-strip-types bench.js&lt;/code&gt; after constructing the client as &lt;code&gt;new PrismaClient({ adapter: new PrismaBetterSqlite3({ url: dbFile }) })&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;node_modules&lt;/code&gt; size: &lt;code&gt;du -sb node_modules&lt;/code&gt; in each project, before you install anything else.&lt;/p&gt;

&lt;p&gt;A process that stays up between requests only pays that 236ms once, then keeps the 3x read speed-up for every query after. A function that gets a fresh container on most invocations pays it almost every time and rarely stays warm long enough to earn the 3x back. Which bucket a given deployment falls into isn't something the Prisma changelog can tell you, so it's worth timing &lt;code&gt;$connect()&lt;/code&gt; to first query on the actual driver adapter for your actual database, not mine on SQLite, before moving anything that scales to zero onto 7.10.1.&lt;/p&gt;

</description>
      <category>node</category>
      <category>database</category>
      <category>performance</category>
      <category>javascript</category>
    </item>
    <item>
      <title>PostgreSQL 19's pg_stat_lock only counts waits that cross deadlock_timeout</title>
      <dc:creator>Alex Georgiev</dc:creator>
      <pubDate>Thu, 05 Nov 2026 11:00:00 +0000</pubDate>
      <link>https://dev.to/alexgeorgiev17/postgresql-19s-pgstatlock-only-counts-waits-that-cross-deadlocktimeout-15lj</link>
      <guid>https://dev.to/alexgeorgiev17/postgresql-19s-pgstatlock-only-counts-waits-that-cross-deadlocktimeout-15lj</guid>
      <description>&lt;p&gt;I set up a row-locking contention test against PostgreSQL 19rc1 to see what its new &lt;code&gt;pg_stat_lock&lt;/code&gt; view actually captures, and the first four runs reported nothing at all. Not zero waits with a caveat. Zero rows changed, full stop, on a view that is supposed to be a cumulative counter of lock waits.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pg_stat_lock&lt;/code&gt; is new in PostgreSQL 19, still a release candidate as of this week. It's a cluster-wide, cumulative view with one row per lock type, meant to answer a question that used to require either polling &lt;code&gt;pg_locks&lt;/code&gt; and hoping you caught the contention in the act, or turning on &lt;code&gt;log_lock_waits&lt;/code&gt; and grepping log files. I pulled &lt;code&gt;postgres:19rc1&lt;/code&gt; from Docker Hub, ran it, and tried to break the view.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the view looks like
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;                        &lt;span class="k"&gt;View&lt;/span&gt; &lt;span class="nv"&gt;"pg_catalog.pg_stat_lock"&lt;/span&gt;
      &lt;span class="k"&gt;Column&lt;/span&gt;       &lt;span class="o"&gt;|&lt;/span&gt;           &lt;span class="k"&gt;Type&lt;/span&gt;           &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;Collation&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;Nullable&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;Default&lt;/span&gt;
&lt;span class="c1"&gt;-------------------+--------------------------+-----------+----------+---------&lt;/span&gt;
 &lt;span class="n"&gt;locktype&lt;/span&gt;          &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;text&lt;/span&gt;                     &lt;span class="o"&gt;|&lt;/span&gt;           &lt;span class="o"&gt;|&lt;/span&gt;          &lt;span class="o"&gt;|&lt;/span&gt;
 &lt;span class="n"&gt;waits&lt;/span&gt;             &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;bigint&lt;/span&gt;                   &lt;span class="o"&gt;|&lt;/span&gt;           &lt;span class="o"&gt;|&lt;/span&gt;          &lt;span class="o"&gt;|&lt;/span&gt;
 &lt;span class="n"&gt;wait_time&lt;/span&gt;         &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;double&lt;/span&gt; &lt;span class="nb"&gt;precision&lt;/span&gt;         &lt;span class="o"&gt;|&lt;/span&gt;           &lt;span class="o"&gt;|&lt;/span&gt;          &lt;span class="o"&gt;|&lt;/span&gt;
 &lt;span class="n"&gt;fastpath_exceeded&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;bigint&lt;/span&gt;                   &lt;span class="o"&gt;|&lt;/span&gt;           &lt;span class="o"&gt;|&lt;/span&gt;          &lt;span class="o"&gt;|&lt;/span&gt;
 &lt;span class="n"&gt;stats_reset&lt;/span&gt;       &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;timestamp&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;time&lt;/span&gt; &lt;span class="k"&gt;zone&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;           &lt;span class="o"&gt;|&lt;/span&gt;          &lt;span class="o"&gt;|&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Twelve rows out of the box, one for each lock type PostgreSQL tracks internally: &lt;code&gt;relation&lt;/code&gt;, &lt;code&gt;extend&lt;/code&gt;, &lt;code&gt;frozenid&lt;/code&gt;, &lt;code&gt;page&lt;/code&gt;, &lt;code&gt;tuple&lt;/code&gt;, &lt;code&gt;transactionid&lt;/code&gt;, &lt;code&gt;virtualxid&lt;/code&gt;, &lt;code&gt;spectoken&lt;/code&gt;, &lt;code&gt;object&lt;/code&gt;, &lt;code&gt;userlock&lt;/code&gt;, &lt;code&gt;advisory&lt;/code&gt;, &lt;code&gt;applytransaction&lt;/code&gt;. All zero on a fresh cluster.&lt;/p&gt;

&lt;h2&gt;
  
  
  The first result was nothing, and that was the real finding
&lt;/h2&gt;

&lt;p&gt;My first test was simple: one session takes &lt;code&gt;SELECT * FROM accounts WHERE id=1 FOR UPDATE&lt;/code&gt;, holds it for 200ms, a second session tries the same row, and I check &lt;code&gt;pg_stat_lock&lt;/code&gt; afterwards. I measured the second session's wait at 186ms with a stopwatch in the test harness. &lt;code&gt;pg_stat_lock&lt;/code&gt; showed twelve rows of zero.&lt;/p&gt;

&lt;p&gt;My first assumption was that PostgreSQL's statistics collector batches writes and I just hadn't waited long enough. I checked again after a 2-second delay. Still zero. So I ran the same test with a 3-second hold instead of 200ms, and it worked immediately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;locktype     | waits | wait_time | fastpath_exceeded |          stats_reset
--------------+-------+-----------+-------------------+-------------------------------
transactionid |     1 |  2991.719 |                 0 | 2026-11-05 05:09:52+00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That ruled out a stats-flush delay and pointed at a duration threshold instead. I binary-searched it by holding the lock for increasing durations and checking whether &lt;code&gt;pg_stat_lock&lt;/code&gt; recorded anything:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Actual wait&lt;/th&gt;
&lt;th&gt;Recorded?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;490ms&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;936ms&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;986ms&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;999ms&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1037ms&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;yes&lt;/strong&gt;, wait_time 1035.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1089ms&lt;/td&gt;
&lt;td&gt;yes, wait_time 1089.7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The cutoff sits right at one second, which is PostgreSQL's default &lt;code&gt;deadlock_timeout&lt;/code&gt;. I confirmed it isn't a coincidence by lowering &lt;code&gt;deadlock_timeout&lt;/code&gt; to 200ms and rerunning the same sweep:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Actual wait&lt;/th&gt;
&lt;th&gt;Recorded?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;134ms&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;189ms&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;199ms&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;235ms&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;yes&lt;/strong&gt;, wait_time 235.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;288ms&lt;/td&gt;
&lt;td&gt;yes, wait_time 288.0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The threshold moved with the setting. &lt;code&gt;pg_stat_lock&lt;/code&gt; isn't sampling or batching short waits at a lower weight, it is simply not instrumented at the point where a lock wait begins. It's instrumented at the point where PostgreSQL would otherwise run a deadlock check, which only happens after a backend has been waiting for &lt;code&gt;deadlock_timeout&lt;/code&gt;. Anything that resolves before that point leaves no trace anywhere in this view.&lt;/p&gt;

&lt;h2&gt;
  
  
  It isn't a new gap, it's the same old gap
&lt;/h2&gt;

&lt;p&gt;Before &lt;code&gt;pg_stat_lock&lt;/code&gt;, the way to see lock waits in the logs was &lt;code&gt;log_lock_waits&lt;/code&gt;, which logs a line when a backend has been waiting past &lt;code&gt;deadlock_timeout&lt;/code&gt;. I turned it on and ran a wait at 150ms (below my 200ms &lt;code&gt;deadlock_timeout&lt;/code&gt;) and a wait at 400ms (above it):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2026-11-05 05:12:18.739 UTC LOG:  process 251 still waiting for ShareLock on transaction 718 after 200.214 ms
2026-11-05 05:12:18.775 UTC LOG:  process 251 acquired ShareLock on transaction 718 after 235.648 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only the 400ms wait produced any log line, and &lt;code&gt;pg_stat_lock&lt;/code&gt; recorded 235.648ms as &lt;code&gt;wait_time&lt;/code&gt;, an exact match to the log entry. The 150ms wait left nothing in either place. So &lt;code&gt;pg_stat_lock&lt;/code&gt; isn't worse than what came before it. It's built on the same signal &lt;code&gt;log_lock_waits&lt;/code&gt; has always used, just without needing to parse text files. If you were relying on &lt;code&gt;log_lock_waits&lt;/code&gt; to catch contention, you already had this blind spot and didn't know it had a name.&lt;/p&gt;

&lt;h2&gt;
  
  
  What ten queued sessions actually wait on
&lt;/h2&gt;

&lt;p&gt;I wanted to know whether queued waiters pile onto one counter or split across lock types, so I ran one holder and then 1, 10, 25 and 50 sessions all requesting the same row &lt;code&gt;FOR UPDATE&lt;/code&gt;, with the hold long enough (1.2 seconds) to clear the threshold.&lt;/p&gt;

&lt;p&gt;With 10 waiters, &lt;code&gt;pg_stat_lock&lt;/code&gt; showed this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;locktype&lt;/th&gt;
&lt;th&gt;waits&lt;/th&gt;
&lt;th&gt;wait_time (ms)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;transactionid&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1199.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;tuple&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;10829.3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Only the first waiter in the queue counts against &lt;code&gt;transactionid&lt;/code&gt;; it is waiting directly on the holding transaction's ID to finish. Every other queued session counts against &lt;code&gt;tuple&lt;/code&gt; instead, because PostgreSQL has them queue on a short-lived tuple lock behind the first waiter rather than all piling onto the same transaction ID lock. At 50 waiters the pattern held exactly: 1 &lt;code&gt;transactionid&lt;/code&gt; wait and 49 &lt;code&gt;tuple&lt;/code&gt; waits, averaging about 1.23 seconds each as the queue drained. Nothing degraded or stalled; the 50th waiter wasn't dramatically worse off than the 10th. But the split between &lt;code&gt;transactionid&lt;/code&gt; and &lt;code&gt;tuple&lt;/code&gt; isn't something I'd have guessed from the view's own description as "lock waits by type," and it means a dashboard built on this view needs to know to add both rows together to get "how much contention is actually happening on rows," not just look at the type a reader would naturally assume, &lt;code&gt;tuple&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  It is not a live view
&lt;/h2&gt;

&lt;p&gt;I checked whether &lt;code&gt;pg_stat_lock&lt;/code&gt; updates while a wait is still happening, since that would make it usable as a "who is blocked right now" signal in a monitoring query. I queried it 1.6 seconds into a 3-second wait:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mid-wait (1.6s into a 3s wait): all twelve rows at waits=0
after resolution: transactionid waits=1, wait_time=3000.263
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing shows up until the wait ends. This confirms &lt;code&gt;pg_stat_lock&lt;/code&gt; is a history of waits that have already finished, not a gauge of what's blocked right now. For "what is blocked at this instant," you still need &lt;code&gt;pg_locks&lt;/code&gt; or &lt;code&gt;pg_stat_activity.wait_event&lt;/code&gt;. The two views answer different questions and neither replaces the other: &lt;code&gt;pg_locks&lt;/code&gt; tells you what's stuck now, &lt;code&gt;pg_stat_lock&lt;/code&gt; tells you how often and for how long over the last hour, day, or since the last reset.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it refuses to let you do
&lt;/h2&gt;

&lt;p&gt;Reading the view needs no special privilege. I created a plain role with no grants at all and it could &lt;code&gt;SELECT * FROM pg_stat_lock&lt;/code&gt; without issue, same as any other &lt;code&gt;pg_stat_*&lt;/code&gt; view. Resetting it is a different story:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR:  permission denied for function pg_stat_reset_shared
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I tried this as a role granted &lt;code&gt;pg_monitor&lt;/code&gt;, which normally gets you read access to almost everything observability-related in PostgreSQL. It still got denied. Only superuser can reset &lt;code&gt;pg_stat_lock&lt;/code&gt;'s counters. If your monitoring account runs as a &lt;code&gt;pg_monitor&lt;/code&gt;-scoped role, which is the recommended practice, it can read this view all day but can't clear it, and will need a separate superuser path if you ever want &lt;code&gt;pg_stat_reset_shared('lock')&lt;/code&gt; scripted.&lt;/p&gt;

&lt;p&gt;I also tried a bad target name to see what PostgreSQL would say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR:  unrecognized reset target: "locks"
HINT:  Target must be "archiver", "bgwriter", "checkpointer", "io", "lock", "recovery_prefetch", "slru", or "wal".
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;lock&lt;/code&gt; (singular) is confirmed as a real target in that list, which is a small but easy mistake to make from memory since the view itself is named &lt;code&gt;pg_stat_lock&lt;/code&gt; and the function wants &lt;code&gt;'lock'&lt;/code&gt;, not &lt;code&gt;'locks'&lt;/code&gt; or &lt;code&gt;'lock_waits'&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  One thing I could not trigger
&lt;/h2&gt;

&lt;p&gt;The view has a &lt;code&gt;fastpath_exceeded&lt;/code&gt; column, meant to count when a backend's fast-path lock slots (used for cheap relation-level locks) overflow into the slower shared lock table. I opened a transaction, selected from 40 separate tables inside it, and &lt;code&gt;fastpath_exceeded&lt;/code&gt; stayed at zero across every locktype. I don't know whether the actual threshold is just higher than 40 distinct relations in PostgreSQL 19, or whether triggering it needs a different access pattern than plain &lt;code&gt;SELECT&lt;/code&gt;s. I'm reporting this as unverified rather than claiming either explanation.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong on the way
&lt;/h2&gt;

&lt;p&gt;My first attempt at the 10/25/50-waiter concurrency test hung forever. I'd built it around a &lt;code&gt;threading.Barrier&lt;/code&gt; sized for "holder plus N waiters," but only the holder thread and my own main thread ever called &lt;code&gt;.wait()&lt;/code&gt; on it, the waiter threads didn't. With one waiter this accidentally worked, because the barrier only needed two arrivals and got them by coincidence. With five or more waiters it needed more arrivals than would ever come, and the whole test sat there for minutes doing nothing while I assumed PostgreSQL was just slow. &lt;code&gt;pg_stat_activity&lt;/code&gt; showed the real story immediately: one session sitting &lt;code&gt;idle in transaction&lt;/code&gt; on a completed lock grab, and nothing else happening at all. The fix was to have every waiter thread call &lt;code&gt;barrier.wait()&lt;/code&gt; and to stop having the main thread call it too, since that was eating one of the arrival slots before any waiter thread had even started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; pgtest &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 55432:5432 postgres:19rc1
docker &lt;span class="nb"&gt;exec &lt;/span&gt;pgtest psql &lt;span class="nt"&gt;-U&lt;/span&gt; postgres &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"CREATE TABLE accounts (id int primary key, balance int);"&lt;/span&gt;
docker &lt;span class="nb"&gt;exec &lt;/span&gt;pgtest psql &lt;span class="nt"&gt;-U&lt;/span&gt; postgres &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"INSERT INTO accounts VALUES (1, 100);"&lt;/span&gt;
docker &lt;span class="nb"&gt;exec &lt;/span&gt;pgtest psql &lt;span class="nt"&gt;-U&lt;/span&gt; postgres &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"SELECT pg_stat_reset_shared('lock');"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the harness, trimmed to the single-waiter case that found the threshold in the first place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;psycopg2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;

&lt;span class="n"&gt;DSN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;host=127.0.0.1 port=55432 user=postgres password=test dbname=postgres&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;holder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hold_ms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;psycopg2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DSN&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;autocommit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BEGIN;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SELECT * FROM accounts WHERE id=1 FOR UPDATE;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;wait&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hold_ms&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1000.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;COMMIT;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;waiter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;psycopg2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DSN&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;autocommit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;wait&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;t0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perf_counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BEGIN;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SELECT * FROM accounts WHERE id=1 FOR UPDATE;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;perf_counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;t0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1000.0&lt;/span&gt;
    &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;COMMIT;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;barrier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Barrier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;th&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;holder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1050&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="n"&gt;th&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;waiter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;barrier&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;th&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;waiter waited&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ms&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then check &lt;code&gt;SELECT * FROM pg_stat_lock WHERE waits &amp;gt; 0;&lt;/code&gt; and compare against the number this script printed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do with this
&lt;/h2&gt;

&lt;p&gt;If you plan to alert on &lt;code&gt;pg_stat_lock&lt;/code&gt;, know what it won't tell you. It will not catch the common case of row contention that resolves in a few hundred milliseconds under normal application load, which is most lock contention most applications see. It is built for the slow, deadlock-check-adjacent tail, not the everyday jitter. If you need visibility into sub-second waits, you still need &lt;code&gt;pg_locks&lt;/code&gt; sampled frequently, or you need to lower &lt;code&gt;deadlock_timeout&lt;/code&gt;, which changes how aggressively PostgreSQL runs deadlock detection cluster-wide and is not a change to make only for observability reasons without thinking through the cost. And if you're building a dashboard that reports "lock contention by type," remember that one blocked row under contention from several sessions shows up as one &lt;code&gt;transactionid&lt;/code&gt; wait and several &lt;code&gt;tuple&lt;/code&gt; waits, not several waits of the same type.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>database</category>
      <category>performance</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
