<?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: Rodion Kazennov</title>
    <description>The latest articles on DEV Community by Rodion Kazennov (@nefayran).</description>
    <link>https://dev.to/nefayran</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%2F3643130%2Fc65fbbf1-6ab9-44e2-a28e-96e69769e9ce.jpg</url>
      <title>DEV Community: Rodion Kazennov</title>
      <link>https://dev.to/nefayran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nefayran"/>
    <language>en</language>
    <item>
      <title>Typing 4500000.5 or 4500000,5 into our yen field gave 45,000,005, ten times too much, in 9 of 14 replayed cases</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Mon, 30 Nov 2026 13:10:01 +0000</pubDate>
      <link>https://dev.to/nefayran/typing-45000005-or-45000005-into-our-yen-field-gave-45000005-ten-times-too-much-in-9-of-14-51nf</link>
      <guid>https://dev.to/nefayran/typing-45000005-or-45000005-into-our-yen-field-gave-45000005-ten-times-too-much-in-9-of-14-51nf</guid>
      <description>&lt;p&gt;A salary calculator of ours turned the text 4500000.5 into 45,000,005 yen and showed a take-home figure for a salary ten times bigger than the one typed. It did this with no warning, in 9 of the 14 cases the agents replayed through the first version of the field: two ways of typing a half yen (a dot, 4500000.5, and a comma, 4500000,5), in each of our seven page languages. The dot failed in 2 of the 7 languages and the comma in all 7. After one commit that rewrote both the input code and the validator it happened in 0 of 14, and all 14 now ask for a whole yen amount instead.&lt;/p&gt;

&lt;p&gt;I run an experiment: AI coding agents build and test a set of tools for people living in Japan, and I direct them and check what they report. I did not write this code by hand. The page that matters here is the &lt;a href="https://allkeep.org/en/japan/tools/net-salary?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-11-26-yen-field-ten-times-too-big" rel="noopener noreferrer"&gt;net salary calculator&lt;/a&gt;, part of Japan Life Hub: you type your yearly pay before tax in yen and it shows what lands in your account each month after tax, pension and health insurance. You can try the field yourself there.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the field used to do
&lt;/h2&gt;

&lt;p&gt;The amount boxes in these calculators were &lt;code&gt;&amp;lt;input type="number"&amp;gt;&lt;/code&gt;. A salary of 5000000 showed as raw digits, which is hard to read, so the agents replaced it with a text field that groups digits as you type: &lt;code&gt;5,000,000&lt;/code&gt; in English, &lt;code&gt;5.000.000&lt;/code&gt; in Vietnamese and Indonesian, &lt;code&gt;50,00,000&lt;/code&gt; in Hindi (the Indian system, with a group of two digits). The phone gets the number pad through &lt;code&gt;inputMode="numeric"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Just before that, the agents had found that eight of the calculators dropped the result without a word when the amount was empty, zero or negative, and accepted &lt;code&gt;99999999999&lt;/code&gt; or &lt;code&gt;4500000.5&lt;/code&gt; as if they were fine. They had added &lt;code&gt;parseYenAmount&lt;/code&gt;, which reads a whole amount from 1 to 100,000,000 yen and otherwise puts one line under the field, in the page's language: "Enter {field} in yen as a whole amount from ¥1 to ¥{maximum}."&lt;/p&gt;

&lt;p&gt;Two pieces of code were involved: one reformats what you type, the other decides whether the result is a valid amount, and both caused the comma failure. The first validator (commit 24494b4e) ran &lt;code&gt;replace(/[¥,\s]/g, "")&lt;/code&gt; before reading the number, and the first formatter (2850739b, &lt;code&gt;stripYenInputCharacters&lt;/code&gt;) ran &lt;code&gt;replace(/[¥,]/g, "")&lt;/code&gt;, so each dropped every comma in every language and a typed &lt;code&gt;4500000,5&lt;/code&gt; turned into &lt;code&gt;45000005&lt;/code&gt; before any check. That is 7 of the 9 failures. The other 2 of the 9 are the dot, which sits in the formatter: on the id and vi pages, where the dot is the group separator, it removed every dot, including the ones the visitor typed, because it could not tell the separator it had put there from one you had just typed. The en, ja, ru, hi and zh pages kept 4500000.5 and showed the line.&lt;/p&gt;

&lt;h2&gt;
  
  
  The dot that means two things
&lt;/h2&gt;

&lt;p&gt;In English, the separator between thousands is a comma and a dot is a decimal point. In Vietnamese and Indonesian it is the other way round: the dot groups the thousands. Our formatter asks the browser which separator the page language uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// shortened from yen-input.ts; the comments marked "added" are ours, not in the original&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;yenGrouping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&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;numberLocale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;locale&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"hi"&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"en-IN"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// added: Hindi gets Indian grouping, 50,00,000&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NumberFormat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numberLocale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;maximumFractionDigits&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="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;formatToParts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123456789012345&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;separator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;part&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;part&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"group"&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;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// added: groups = sizes of the integer chunks, e.g. [3, 3, 3, 3, 3] or [3, 2, 2, 2, 2, 2]&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;groups&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"integer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;separator&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;In &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;vi&lt;/code&gt; that separator is &lt;code&gt;.&lt;/code&gt;. When you type, the code removes the separator and puts it back in the right places, so the field can show &lt;code&gt;4.500.000&lt;/code&gt; and keep the digits &lt;code&gt;4500000&lt;/code&gt; underneath.&lt;/p&gt;

&lt;p&gt;So you type &lt;code&gt;4500000.5&lt;/code&gt; into a Vietnamese page. The field removes the dot, keeps &lt;code&gt;45000005&lt;/code&gt;, and draws it as &lt;code&gt;45.000.005&lt;/code&gt;. The validator sees a whole number between 1 and 100,000,000 and is satisfied. The calculator does the rest, for a salary ten times too big.&lt;/p&gt;

&lt;p&gt;The agents' own live check found the dot. The fix commit (9be3dd6e) gives 10 of 280 cases for the dot in id and vi and no count for the comma. Its title names &lt;code&gt;4500000,5&lt;/code&gt; and the same commit fixes the decimal comma, while the replay below shows the first version failing on the comma in all 7 languages. I did not rerun the 280 and do not have the list; the replay uses a smaller set.&lt;/p&gt;

&lt;h2&gt;
  
  
  Replaying typing through both versions
&lt;/h2&gt;

&lt;p&gt;I wanted the number to come from running the code. The two versions of &lt;code&gt;yen-input.ts&lt;/code&gt; are in git, so a short script written for this article types a string one character at a time into each version, exactly as the component would call it: the previous value, the text the browser reports, the cursor at the end, and the option that keeps text that is not an amount so the warning can show. Then it asks &lt;code&gt;parseYenAmount&lt;/code&gt; what the calculator would receive.&lt;/p&gt;

&lt;p&gt;The inputs: &lt;code&gt;4500000.5&lt;/code&gt;, &lt;code&gt;4500000,5&lt;/code&gt;, &lt;code&gt;4,500,000&lt;/code&gt;, &lt;code&gt;4.500.000&lt;/code&gt;, &lt;code&gt;-500000&lt;/code&gt;, &lt;code&gt;99999999999&lt;/code&gt; and &lt;code&gt;4500000&lt;/code&gt;, in the seven page languages (en, ja, ru, hi, zh, id, vi). The agents count two of them as the failure: a half yen typed with a dot and a half yen typed with a comma. That is 14 cases.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fek9s4ied8d9b1p9bdqzl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fek9s4ied8d9b1p9bdqzl.png" alt="A grid of 7 page languages by 2 typed inputs: the first version of the field gives 45,000,005 yen in 9 of 14 cells, the current version shows the warning line in all 14" width="800" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the chart, the bottom two rows are the current version, where the line under the field shows.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Typed&lt;/th&gt;
&lt;th&gt;First version: wrong amount&lt;/th&gt;
&lt;th&gt;Current version: wrong amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;4500000.5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2 of 7 languages (id, vi)&lt;/td&gt;
&lt;td&gt;0 of 7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;4500000,5&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;7 of 7 languages&lt;/td&gt;
&lt;td&gt;0 of 7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Total&lt;/td&gt;
&lt;td&gt;9 of 14&lt;/td&gt;
&lt;td&gt;0 of 14&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The other five inputs behaved the same in both versions, apart from the one I come back to at the end. &lt;code&gt;-500000&lt;/code&gt; and &lt;code&gt;99999999999&lt;/code&gt; were never taken for amounts, and a plain &lt;code&gt;4500000&lt;/code&gt; was read as 4,500,000 everywhere (replay rerun on 27.11).&lt;/p&gt;

&lt;p&gt;The 9 of 14 counts the cases the agents chose for the replay, and I have no data on how often a stray dot or comma lands in this field. The replay covers typing only; pasting goes down a different path.&lt;/p&gt;

&lt;p&gt;By commit times, which are not deploy times, the first formatter (2850739b) went in on 24.11 at 14:15Z and the fix (9be3dd6e, after the agents' live check) at 14:46Z, 31 minutes later.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: compare with what the field showed
&lt;/h2&gt;

&lt;p&gt;The rewrite stopped guessing which characters were separators. It compares what the browser now reports with what the field had displayed before the edit, finds the part that changed, and treats everything outside that part as the field's own text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// shortened from yen-input.ts; comments added&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;findEdit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;displayed&lt;/span&gt;&lt;span class="p"&gt;:&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;raw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&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;prefix&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="c1"&gt;// characters unchanged at the start&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefix&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;displayed&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="n"&gt;raw&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="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;displayed&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="o"&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;suffix&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="c1"&gt;// characters unchanged at the end&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;suffix&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;displayed&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="n"&gt;raw&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="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;prefix&lt;/span&gt;
      &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;displayed&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;displayed&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="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;suffix&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;raw&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="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;suffix&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;suffix&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;inserted&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;raw&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="n"&gt;suffix&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only separators in the unchanged prefix and suffix, which the field itself put there, are removed. What the visitor inserted keeps its dots and commas, unless it is a well-formed grouped amount, such as a pasted &lt;code&gt;5.000.000&lt;/code&gt; in Vietnamese or &lt;code&gt;5,000,000&lt;/code&gt; anywhere. The validator also changed: a comma is now accepted only as a thousands separator, with this check:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// from amount-validation.ts; the comment after the regex is added&lt;/span&gt;
&lt;span class="o"&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;d&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="mi"&gt;3&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;d&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;3&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;d&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="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="p"&gt;,&lt;/span&gt;\&lt;span class="n"&gt;d&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="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;d&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;3&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="c1"&gt;// 4,500,000 and 45,00,000 pass; 4500000,5 does not&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second alternative is there for Indian grouping. A stray &lt;code&gt;.5&lt;/code&gt; or &lt;code&gt;,5&lt;/code&gt; now stays in the box, fails the whole-yen test, and the line under the field says what to type.&lt;/p&gt;

&lt;p&gt;The field is live in the &lt;a href="https://allkeep.org/en/japan/tools/net-salary?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-11-26-yen-field-ten-times-too-big" rel="noopener noreferrer"&gt;net salary calculator&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The question I am left with
&lt;/h2&gt;

&lt;p&gt;The replay has one input that got worse, outside the table and chart: &lt;code&gt;4.500.000&lt;/code&gt; typed on the id and vi pages. The field cannot tell whether that typed dot is a thousands separator or a decimal point, and a hand-typed dot is kept as typed, so the new rule refuses it with the line under the field. The first version accepted it as 4,500,000, which is what a Vietnamese reader meant. A pasted &lt;code&gt;4.500.000&lt;/code&gt; still works. On those two pages a typed &lt;code&gt;4,500,000&lt;/code&gt; (a comma, which is their decimal mark) is accepted in both versions.&lt;/p&gt;

&lt;p&gt;The fix trades a silent amount ten times too big for a warning. I have no number for how many people type their dots in those two languages, and the agents did not collect one. When a dot is both the thousands mark and what some visitors use as a decimal point, should a text field accept a typed &lt;code&gt;4.500.000&lt;/code&gt; and guess, or refuse and explain?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>i18n</category>
      <category>japan</category>
    </item>
    <item>
      <title>A white halo on a Godot planet: one commit cut the edge's sharpest brightness drop from 188 to 40 (of 255)</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Thu, 26 Nov 2026 15:38:53 +0000</pubDate>
      <link>https://dev.to/nefayran/a-white-halo-on-a-godot-planet-one-commit-cut-the-edges-sharpest-brightness-drop-from-188-to-40-250f</link>
      <guid>https://dev.to/nefayran/a-white-halo-on-a-godot-planet-one-commit-cut-the-edges-sharpest-brightness-drop-from-188-to-40-250f</guid>
      <description>&lt;p&gt;The menu of our game shows a planet from orbit, and its blue atmosphere glow looked wrong: a white band, cut off against the sky in little steps. One commit, which changed the order in which things are drawn and the glow shader, took the sharpest brightness fall at the planet's edge from 188 to 40 (out of 255) and the near-white pixels around it from 1,171 to 3, measured on frames of the built game at 1440x900.&lt;/p&gt;

&lt;p&gt;The game is &lt;a href="https://allkeep.org/en/products?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-11-25-planet-edge-white-pixels" rel="noopener noreferrer"&gt;Planet Wanderer&lt;/a&gt;, and it is an experiment: AI coding agents write it in Godot 4, and I direct them, play the builds and check what they measure. It is not released, so there is nothing to download yet, and its code is not public, so the file names below are for orientation only. The card on that page is where it lives for now.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it looked like
&lt;/h2&gt;

&lt;p&gt;From orbit, a planet with an atmosphere has a thin rim of lit air, thickest at the edge because that is where your line of sight crosses the most air. Our menu planet drew this rim with a shell of air around the ground, added on top of the picture.&lt;/p&gt;

&lt;p&gt;On screen the rim was a bright, almost white band, and its outer edge ran in stair steps. The steps followed the hexagonal columns that the planet's ground is built from. Some cloud heaps near the edge were cut the same way.&lt;/p&gt;

&lt;p&gt;The commit's comments put the stair-stepped band down to draw order: the glow was painted over after it was drawn. The white came from the old glow formula, &lt;code&gt;col * rim * lit * strength&lt;/code&gt;, which had no upper limit, so the glow that survived clipped to white. The commit changed both.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cause: who is drawn after whom
&lt;/h2&gt;

&lt;p&gt;A Godot 3D scene draws see-through things in an order, and the engine sorts them by distance unless you set a priority. Our air shell does not test depth and does not write depth. The galaxy backdrop behind the planet is not opaque to Godot: its shader writes ALPHA, so Godot sorts it with the transparent things, and centred on the camera it came last.&lt;/p&gt;

&lt;p&gt;So the galaxy painted over the glow. The glow survived only on screen pixels where a solid ground column stood in front of the galaxy: the ground wrote depth there, and the farther galaxy failed the depth test. Those pixels follow the outline of the hex columns. A glow visible only where hex columns stand in front of it is a stair-stepped band. The surviving glow came from the uncapped formula and clipped to white, which is why the band was white.&lt;/p&gt;

&lt;p&gt;The fix is one commit with four parts, plus new defaults:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The air shell gets an explicit render priority so it is drawn last, after the galaxy and the cloud heaps.&lt;/li&gt;
&lt;li&gt;It switches from additive blending to premultiplied alpha, and its colour saturates softly instead of clipping: &lt;code&gt;glow = 1.0 - exp(-col * rim * lit * strength)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A hard &lt;code&gt;if (b &amp;lt; surf_r)&lt;/code&gt; that switched between "air over the ground" and "air at the rim" became a smooth blend over a 16 m band (8 m each side of the ground's edge). The old switch cut a visible ring against the hex edge.&lt;/li&gt;
&lt;li&gt;Cloud heaps now fade out on view rays that miss the planet, so they do not end in the same stair steps.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The same commit lowered the menu's air strength from 4.2 to 2.0 and narrowed the air shell's span, its height over the ground, from 130 m to 70 m.&lt;/p&gt;

&lt;p&gt;No run measures one part alone, so I credit the commit as a whole. Parts 2 to 4 are shader changes.&lt;/p&gt;

&lt;p&gt;Part 1 is two lines (shortened; the comment is rewritten for this article):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="n"&gt;const&lt;/span&gt; &lt;span class="no"&gt;AIR_PRIORITY&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;   &lt;span class="c1"&gt;# after the galaxy and the cloud heaps (both 0) and another haze layer (1)&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;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;render_priority&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;AIR_PRIORITY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How we measured an edge
&lt;/h2&gt;

&lt;p&gt;"Looks smoother" is hard to compare by eye between two screenshots, so the agents wrote a script, &lt;code&gt;tools/rim_measure.py&lt;/code&gt;, and ran it on screenshots of the built game on Windows, before and after, same world and same window size.&lt;/p&gt;

&lt;p&gt;For each frame it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fits a circle to the planet's disc once, on the first frame;&lt;/li&gt;
&lt;li&gt;walks the lit side of the edge every half degree, 300 rays in all;&lt;/li&gt;
&lt;li&gt;along each ray reads brightness from 0.92 to 1.30 of the radius;&lt;/li&gt;
&lt;li&gt;records the largest one-pixel fall in brightness outside the disc, and takes the 95th percentile over all rays (call it the jump);&lt;/li&gt;
&lt;li&gt;counts near-white pixels (all channels above 225) in a ring just outside the disc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A white band cut off against the sky falls by over 100 in one pixel. A glow that fades out falls by a few tens. The script has 106 lines; its core, shortened:&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;# the comments below are written for this article; the code is shortened from rim_measure.py&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;deg&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;150.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;300.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;                    &lt;span class="c1"&gt;# lit side, 300 rays&lt;/span&gt;
    &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;radians&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;rs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.92&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&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;sample&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;L&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cx&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;rs&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cy&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;rs&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# brightness along the ray&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rs&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.995&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;                                &lt;span class="c1"&gt;# outside the disc&lt;/span&gt;
    &lt;span class="n"&gt;jumps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;out&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="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="c1"&gt;# biggest fall over one pixel (2 samples)&lt;/span&gt;
&lt;span class="n"&gt;jump_p95&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;percentile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jumps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;95&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ring&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rr&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rr&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                     &lt;span class="c1"&gt;# rr = distance from the disc centre&lt;/span&gt;
&lt;span class="n"&gt;white&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="n"&gt;a&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;225&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;225&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;225&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;ring&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&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;It also prints &lt;code&gt;steps_px&lt;/code&gt;, how far the glow's edge wanders between neighbouring rays, which is the stair-step measure itself. The design document records no &lt;code&gt;steps_px&lt;/code&gt; values for these frames, so I give only the jump and the white count.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flxyumn1kl05xsvulm4q8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flxyumn1kl05xsvulm4q8.png" alt="Bars of the planet rim before and after: sharpest one-pixel fall 188 to 40 at 1440x900 and 192 to 38 at 1920x1080; near-white pixels 1,171 to 3 and 1,926 to 39" width="799" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Window&lt;/th&gt;
&lt;th&gt;Jump before&lt;/th&gt;
&lt;th&gt;Jump after&lt;/th&gt;
&lt;th&gt;White pixels before&lt;/th&gt;
&lt;th&gt;White pixels after&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1440x900&lt;/td&gt;
&lt;td&gt;188&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;1,171&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1920x1080&lt;/td&gt;
&lt;td&gt;192&lt;/td&gt;
&lt;td&gt;38&lt;/td&gt;
&lt;td&gt;1,926&lt;/td&gt;
&lt;td&gt;39&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The jump falls by a factor of about five at both sizes. The white-pixel count is the shakier number: an earlier after-fix run, made before the commit was recorded, gave 14 where this one gave 3 (next section). The larger window keeps 39 white pixels, and I do not know yet where they sit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Another run gave 14 white pixels
&lt;/h2&gt;

&lt;p&gt;A comment in the game code says the jump went from 197 to 43 and the white pixels from 1,248 to 14. The table above is the one in the design document, from the exported builds. That comment sits inside the commit itself, so it comes from an earlier after-fix run, made before the commit was recorded, and nothing shows the build was the same. The jump differs by a few percent, but the after-fix white count is 3 in one and 14 in the other, about 4.7 times apart at 1440x900. So I would not trust the white-pixel count, and the 1,171 to 3, to better than a factor of five. I do not know why the after-fix count is 3 in one run and 14 in the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  A test that renders nothing
&lt;/h2&gt;

&lt;p&gt;The agents also added a test, &lt;code&gt;test_orbit_edge.gd&lt;/code&gt;. It does not render anything. It checks that the air shell's material uses &lt;code&gt;AIR_PRIORITY&lt;/code&gt; and that &lt;code&gt;AIR_PRIORITY&lt;/code&gt; is above 1, that the shader uses premultiplied alpha, that the hard &lt;code&gt;if (b &amp;lt; surf_r)&lt;/code&gt; is gone, and that both menu defaults are 2.0 and 70. It never reads the galaxy's priority, so raising the galaxy's would bring the old order back with the test still green.&lt;/p&gt;

&lt;p&gt;It would pass on a shader with the right keywords and a bad look. The measurement lives in the script, which reads any PNG frames of the same world and window; Windows is only where our frames were made.&lt;/p&gt;

&lt;p&gt;For your own project, the part that carries over is small: put your see-through layers in an explicit order, and measure the edge with a script before you tune any colours.&lt;/p&gt;

&lt;h2&gt;
  
  
  The question I am left with
&lt;/h2&gt;

&lt;p&gt;A jump of 40 out of 255 is clearly better than 188. I do not know whether 40 is smooth. Our only threshold is "a glow that fades out falls by a few tens", which the agents wrote in the same commit as the numbers. The measurement also covers only the menu frame; the design document says the white rim also showed on the world-select and flight screens, and those were not measured.&lt;/p&gt;

&lt;p&gt;If you have measured this: what brightness fall per pixel at a planet's edge is the point where a person stops seeing a step, and does it depend on the background behind it?&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>programming</category>
      <category>godot</category>
      <category>shaders</category>
    </item>
    <item>
      <title>We measured our Android app first: 18 pictures were half of its 58.6 MB base APK</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Wed, 25 Nov 2026 12:50:59 +0000</pubDate>
      <link>https://dev.to/nefayran/we-measured-our-android-app-first-18-pictures-were-half-of-its-586-mb-base-apk-1h90</link>
      <guid>https://dev.to/nefayran/we-measured-our-android-app-first-18-pictures-were-half-of-its-586-mb-base-apk-1h90</guid>
      <description>&lt;p&gt;On 22 November I asked for AllKeep Inventory to be measured before anything in it was fixed. On a real phone the app's base APK was 58.6 MB, and 28.8 MB of that was pictures. Eighteen illustrations, each a 1254 by 1254 PNG of 0.9 to 2.2 MB, most shown on screen far smaller than their pixels. This post is the three measurements (an app size, a list, a web page) and the three fixes. The pictures fix has an installed-size number after it (36.2 MB); the Home page fix has no Lighthouse number after it yet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://allkeep.org/en/inventory?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-11-24-android-pictures-half-the-app" rel="noopener noreferrer"&gt;AllKeep Inventory&lt;/a&gt; keeps a list of what you own, room by room and box by box, with photos and values, so there is something to show an insurer after a fire or a burglary. It has a web app and an Android app. It is an experiment: AI coding agents write, test and review it, and I direct them and check what they measure. Every measured number below comes from their runs on 22 November (UTC), and the commands and files are named in the text.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measure first, one pull request per fix
&lt;/h2&gt;

&lt;p&gt;My instruction was short: measure the apps first, fix the slowest parts, and give the number before and after for each fix, one pull request per fix.&lt;/p&gt;

&lt;p&gt;The web pages were measured with Lighthouse 13.6.0 from a headless Chrome, three runs per page and form factor, median taken. The phone run is Lighthouse's default: a simulated Moto G Power on slow 4G with a 4x CPU slowdown. The Android numbers were read over &lt;code&gt;adb&lt;/code&gt; from a phone connected to a computer, on the Play build 1.0.5 (version code 23).&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Half of the base APK was eighteen pictures
&lt;/h2&gt;

&lt;p&gt;On the phone, the installed base APK was 58.6 MB (&lt;code&gt;pm path&lt;/code&gt;, then &lt;code&gt;stat&lt;/code&gt; on the file). The arm64 split next to it was 31.5 MB. Listing the base APK with &lt;code&gt;unzip -l&lt;/code&gt; and keeping what sits under &lt;code&gt;res/drawable-mdpi-v4/assets_images_*&lt;/code&gt; gave 28.8 MB, so about half of the base APK. With the split the installed app was 90.1 MB, and the pictures were about a third of that.&lt;/p&gt;

&lt;p&gt;Those were 18 pictures: 13 empty states ("nothing here yet" screens), 4 onboarding heroes and the logo. All were 1254 by 1254 RGBA PNGs. They are drawn at 160 to 220 dp, at the screen's width, and at 32 to 40 dp respectively. A phone with a density of 3 needs about 660 pixels for a 220 dp picture, and the file had about twice that.&lt;/p&gt;

&lt;p&gt;The fix, in one pull request (#623), converted them to WebP at 768 px for the empty states, 1080 px for the onboarding heroes and 256 px for the logo, and moved the full-size originals out of the app's folder into &lt;code&gt;docs/brand/masters/&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4yxilp04za1qvbhts4zt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4yxilp04za1qvbhts4zt.png" alt="Bars of the 18 bundled pictures before and after: empty states 17.3 MB to 0.9 MB, onboarding 6.6 MB to 1.7 MB, logo 1.4 MB to 0.02 MB" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The sizes in that chart are file sizes in the repository, taken from the commit's diff: 25.3 MB of PNG became 2.6 MB of WebP. The logo went from 1.37 MB to 24.9 KB.&lt;/p&gt;

&lt;p&gt;A test keeps it from coming back. The next person to drop an export from a design tool into the folder would put the 25 MB back without knowing. So the agents wrote a test that opens the three files that &lt;code&gt;require&lt;/code&gt; the pictures, finds every picture they use, and fails on size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pictures&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"%s exists and is at most 512 KiB"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;picture&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="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;existsSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;picture&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;throw&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;`Missing bundled picture: ${picture}`&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;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;statSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;picture&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&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;size&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&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;`Bundled picture ${picture} is ${size} bytes (limit: 524288)`&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A second test in the same file caps the total at 4 MiB. The biggest picture now is the sign-in hero at 505,632 bytes, 18 KB under its limit, and the total is 2.64 MB.&lt;/p&gt;

&lt;p&gt;Cold start was measured in the same pass: &lt;code&gt;am start -S -W&lt;/code&gt;, six runs, 0.73 s (0.71 to 0.80 s). It was already under a second, so it was left alone.&lt;/p&gt;

&lt;p&gt;After the change we installed the next build (version code 24) on the same phone and ran the same two commands: &lt;code&gt;pm path&lt;/code&gt;, then &lt;code&gt;stat&lt;/code&gt; on the base APK. It is 36,203,390 bytes, 36.2 MB, down from 58.6 MB. The commit title had predicted about 35 MB, so the arithmetic was close, and the arm64 split next to it is unchanged at 31.5 MB. One thing is still unexplained: the pictures were 25.3 MB in the repository and 28.8 MB in the APK listing, and nobody has checked whether the build tool adds a copy for another density or whether other files sit under the same path. We did not run the Lighthouse check again after the web fix, so that number stays unmeasured.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. A list that mounted every row
&lt;/h2&gt;

&lt;p&gt;The Inventory tab shows boxes, and below them the things that are not in a box yet. The list was a &lt;code&gt;FlatList&lt;/code&gt;, React Native's virtualized list, but only for the boxes. The unsorted things were rendered in its footer, as ordinary children, so all of them were created at once. With 1,000 unsorted things, rendering the screen in the Jest test renderer mounted 1,000 row components. The fix puts the boxes, the section headers and the rows into one flat list of data for the virtualized list, and the same test now mounts 7 rows. The first 10 cells the list creates also hold 2 boxes and 1 header, which is why it is 7 and not 10.&lt;/p&gt;

&lt;p&gt;The test failed with 1,000 before the change and passes with 7 after it, so the screen no longer builds 993 rows nobody can see. How much smoother it is, we cannot say: the test renderer counts components and does not measure frames or memory on a phone, and the test phone has 14 things in it, too few to time a scroll.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. A web page that scored 34
&lt;/h2&gt;

&lt;p&gt;The landing page and the start page of the web app were fine: 94 and 92 on the phone run, with the largest paint at 1.33 s and 1.06 s. The app's Home, the dashboard a signed-in person sees first, was not:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Home, signed in, 14 things in 4 boxes&lt;/th&gt;
&lt;th&gt;Score&lt;/th&gt;
&lt;th&gt;Largest paint&lt;/th&gt;
&lt;th&gt;Blocking time&lt;/th&gt;
&lt;th&gt;Layout shift&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Phone (simulated)&lt;/td&gt;
&lt;td&gt;34&lt;/td&gt;
&lt;td&gt;5.08 s&lt;/td&gt;
&lt;td&gt;979 ms&lt;/td&gt;
&lt;td&gt;0.548&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Desktop&lt;/td&gt;
&lt;td&gt;76&lt;/td&gt;
&lt;td&gt;1.06 s&lt;/td&gt;
&lt;td&gt;36 ms&lt;/td&gt;
&lt;td&gt;0.523&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Google calls under 0.1 good; both runs were above 0.5, five times that, because the Home component asked for the dashboard numbers and mounted ten cards (fed by 11 requests) only after they came back, and each card then started its own request and appeared whenever it answered. Two rounds of requests, one after the other, and every card that appeared pushed the boxes and the stats down the screen. Nine shifts added up to the 0.55.&lt;/p&gt;

&lt;p&gt;The fix has two parts. A small hook starts all the cards' requests together, at the top of the page. And the dashboard shows once, when everything has answered or failed, or after four seconds, whichever is first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;waitedLong&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setWaitedLong&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;useEffect&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;timer&lt;/span&gt; &lt;span class="o"&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;setWaitedLong&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4000&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="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;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timer&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="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;ready&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="n"&gt;waitedLong&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;settled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dashQ&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;settled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;boxesQ&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isEmpty&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;settled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;catQ&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;cardQs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;settled&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;settled&lt;/code&gt; means the request has data or has failed, so one broken card cannot hold the page. A new account with nothing in it waits only for the counts and the boxes, then shows its first step.&lt;/p&gt;

&lt;p&gt;The same report lists what is still heavy after this change and was left for later: 175 KB of the app page's 505 KB of JavaScript is unused when the page loads, and Lighthouse flags 25 KB of old polyfills.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I still don't know
&lt;/h2&gt;

&lt;p&gt;The Lighthouse run after the Home fix has not been done. The measurement file says so itself: the "after" section is empty, to be filled after the merge and the next Android release. So I know what the page scored before (34, 0.548) and what the fix is meant to do to the layout shift. I do not know what it does to the largest paint.&lt;/p&gt;

&lt;p&gt;Waiting for 14 requests (the dashboard counts, the boxes, the categories and the 11 card hooks) means the cards appear when the slowest one answers, and on a slow connection that is later than the first card would have been. During the wait the reader sees the quick actions and four pulsing grey blocks. The four-second cap bounds the damage, but four seconds of grey blocks can score worse than a page that jumps around. The layout shift should fall to near zero; whether the largest paint falls or rises with it, we will find out when the same script runs again.&lt;/p&gt;

&lt;p&gt;If you want to see what the app is for, &lt;a href="https://allkeep.org/en/inventory?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-11-24-android-pictures-half-the-app" rel="noopener noreferrer"&gt;AllKeep Inventory&lt;/a&gt; is where you can start a list of your own things, room by room, on the web.&lt;/p&gt;

&lt;p&gt;If you have shipped a dashboard of independent cards, which did you pick: one shared placeholder until the slowest card answers, or a placeholder sized to each card, and what did it do to your largest paint on a slow phone?&lt;/p&gt;

</description>
      <category>programming</category>
      <category>performance</category>
      <category>reactnative</category>
      <category>android</category>
    </item>
    <item>
      <title>A third of one kind of lipid left our simulated membrane at a setting where a short test saw none come off</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Tue, 24 Nov 2026 13:41:57 +0000</pubDate>
      <link>https://dev.to/nefayran/a-third-of-one-kind-of-lipid-left-our-simulated-membrane-at-a-setting-where-a-short-test-saw-none-57m8</link>
      <guid>https://dev.to/nefayran/a-third-of-one-kind-of-lipid-left-our-simulated-membrane-at-a-setting-where-a-short-test-saw-none-57m8</guid>
      <description>&lt;p&gt;Our simulated membrane is a flat sheet of two kinds of lipid, and one number, &lt;code&gt;eps_ab&lt;/code&gt;, sets how hard the two kinds pull on each other: at 1.0 as hard as within a kind, at 0.65 about a third weaker. A short test saw five pieces break away from the sheet within 9,000 steps at 0.6, and none off at 0.65 by then. Run three times as long, the sheet at 0.65 lost 31 to 36 % of its minority lipids (two random seeds).&lt;/p&gt;

&lt;p&gt;This is an experiment: my AI agents write the simulation code, run it and measure what comes out, and I direct them and check the numbers. Our earlier membrane simulation, protocell, is listed on &lt;a href="https://allkeep.org/en/lab" rel="noopener noreferrer"&gt;AllKeep Lab&lt;/a&gt;: a GPU run that tried to grow a closed cell membrane from simple molecules and never closed it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a membrane would throw pieces off
&lt;/h2&gt;

&lt;p&gt;A cell membrane is a double layer of fat molecules (lipids), heads facing the water on both sides, tails tucked inside. Real membranes mix many kinds of lipid. When two kinds would rather sit next to their own kind, they gather into patches, and the rim of a patch costs energy, the way the surface of a raindrop does. Physicists call that cost per unit length of rim the line tension.&lt;/p&gt;

&lt;p&gt;A patch can shorten its rim by bulging out of the sheet. A dome has a shorter rim than a flat disc of the same area, and a ball that has pinched off has no rim at all. Bending the sheet costs energy too, so a patch buds off only when its rim costs more than the bend. Reinhard Lipowsky worked this out in the early 1990s (&lt;a href="https://www.mpikg.mpg.de/rl/P/archive/097.pdf" rel="noopener noreferrer"&gt;Biophys. J. 64, 1133, 1993&lt;/a&gt;): a flat patch becomes unstable and buds once it grows past a size set by the membrane's bending stiffness divided by the line tension of the patch's edge.&lt;/p&gt;

&lt;p&gt;So we expected a line. Above some pull between the two kinds, patches stay flat; below it, they bud. The first short test seemed to put that line between 0.65 and 0.6.&lt;/p&gt;

&lt;h2&gt;
  
  
  The model: three beads, no water
&lt;/h2&gt;

&lt;p&gt;The simulation is the lipid model of Cooke, Kremer and Deserno (&lt;a href="https://arxiv.org/abs/cond-mat/0502418" rel="noopener noreferrer"&gt;Phys. Rev. E 72, 011506, 2005&lt;/a&gt;), written from the paper in about 150 lines of C. Each lipid is three beads on springs: one head and two tail beads. There is no water at all. In a real membrane, water pushes the oily tails together; here that push is replaced by a broad attraction between tail beads, and that alone holds the lipids together as a double layer. Units are the model's own: lengths in σ (about one bead), energies in ε (the depth of the tail attraction), time in τ.&lt;/p&gt;

&lt;p&gt;Our version has two kinds of lipid, drawn orange and teal. They are identical in every way but one: how strongly a teal tail pulls an orange tail. That number, &lt;code&gt;eps_ab&lt;/code&gt;, is 1.0 when the pull between kinds is as strong as within a kind. This is the part of the force loop where it enters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taili&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;tailj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                      &lt;span class="cm"&gt;/* both beads are tails */&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;e&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="n"&gt;ti&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;tj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;eab&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r2&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;r&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;RC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;e_&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                   &lt;span class="cm"&gt;/* full depth inside 2^(1/6) sigma */&lt;/span&gt;
    &lt;span class="k"&gt;else&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;r&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;RC&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;wc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                &lt;span class="cm"&gt;/* cos^2 tail out to rc + wc */&lt;/span&gt;
        &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;M_PI&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="no"&gt;RC&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="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;wc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cs_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;e_&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;cs_&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;cs_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;cs_&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;sin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&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="no"&gt;M_PI&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;wc&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;r&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;&lt;code&gt;ti == tj&lt;/code&gt; compares bead types, so an orange tail meeting a teal tail gets &lt;code&gt;eab&lt;/code&gt; instead of 1.0. Everything else is the same for both kinds: the springs, the repulsion between all beads, and the random kicks of a heat bath that keep the temperature at kT = 1.1. The attraction reaches wc = 1.6σ beyond the distance where the repulsion ends, and each step moves time on by 0.01τ.&lt;/p&gt;

&lt;p&gt;The sheet is flat and fills a periodic box 48.4σ on a side: 44 by 44 lipids in each of the two layers, 3,872 lipids and 11,616 beads, 1.1σ apart at the start. Periodic means the sheet has no edges: it leaves one side of the box and comes back in on the other. In the run with no difference between the kinds, the median lipid drifted 3.2σ sideways in 27,000 steps, about three neighbour spacings, and over the 300,000 steps of the sorting run in the next section, 12σ. The lipids wander past each other, so the sheet is a fluid, as a membrane should be.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three short videos, two knobs at once
&lt;/h2&gt;

&lt;p&gt;The first three runs were made as short videos, and each changed two things at once: the share of teal lipids and the pull between the kinds.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;teal lipids&lt;/th&gt;
&lt;th&gt;pull &lt;code&gt;eps_ab&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;steps&lt;/th&gt;
&lt;th&gt;what the measurement says&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;50 %&lt;/td&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;td&gt;300,000&lt;/td&gt;
&lt;td&gt;sorted into patches: among each head's six nearest heads, the share of its own colour rose from 0.50 to 0.93; the sheet stayed one piece&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20 %&lt;/td&gt;
&lt;td&gt;0.6&lt;/td&gt;
&lt;td&gt;100,000&lt;/td&gt;
&lt;td&gt;teal left: 9 pieces of 20+ lipids at the end, the teal share of the sheet down from 20.4 % to 8.6 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;40 %&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;td&gt;150,000&lt;/td&gt;
&lt;td&gt;torn: 16 pieces of 20+ lipids within 3,000 steps of setting the pull to 0.0, and at the end a third of the box's floor plan (32 %) had no membrane over it&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fodnchqryk0qtp784hxl9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fodnchqryk0qtp784hxl9.jpg" alt="The last frame of the budding run at step 100,000: an orange sheet with teal patches bulging out of it, a teal ball just off its top face, teal clumps hanging under it and single teal lipids loose around it" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The middle one looks like budding in its video, whose last frame is above: teal patches swell out of the sheet, above and below, while loose lipids drift away. With two knobs turned at once, though, the three videos cannot say what the pull alone does. So the agents ran a sweep.&lt;/p&gt;

&lt;h2&gt;
  
  
  The sweep
&lt;/h2&gt;

&lt;p&gt;Every run starts from the sheet of the budding video: the same 789 teal lipids out of 3,872, in the same places. Each gets the same warm-up of 3,000 short steps with the pull at 1.0, which lets the freshly built sheet settle, and then 27,000 steps at one pull: 1.0 as the control, 0.8, 0.7, 0.65, 0.6 and 0.5. The two values around the supposed line, 0.65 and 0.6, ran a second time from a warm-up with another random seed, so the heat bath's kicks came out different. The first 0.6 run is the budding video itself, cut at the same 30,000 steps. Seven new runs, two threads each, took 54 minutes on a laptop that was busy with other jobs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5d5vkyf6pl0nnxtweig4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5d5vkyf6pl0nnxtweig4.png" alt="Share of the teal lipids that left the sheet against simulation steps, one line per pull between the two kinds: none at 1.0, about 2 % at 0.8, 23 % at 0.7, 31 to 36 % at 0.65, about half at 0.6 and 95 % at 0.5 by step 30,000" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;pull &lt;code&gt;eps_ab&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;teal off the sheet at step 30,000&lt;/th&gt;
&lt;th&gt;pieces of 20+ lipids&lt;/th&gt;
&lt;th&gt;first piece at step&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1.0 (control)&lt;/td&gt;
&lt;td&gt;0 of 789 (at most 1 in any frame)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;td&gt;14 (1.8 %)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.7&lt;/td&gt;
&lt;td&gt;185 (23 %)&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;23,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.65, two seeds&lt;/td&gt;
&lt;td&gt;285 (36 %) and 244 (31 %)&lt;/td&gt;
&lt;td&gt;8 and 6&lt;/td&gt;
&lt;td&gt;13,000 and 11,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.6, two seeds&lt;/td&gt;
&lt;td&gt;410 (52 %) and 394 (50 %)&lt;/td&gt;
&lt;td&gt;8 and 8&lt;/td&gt;
&lt;td&gt;by 14,000* and 12,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.5&lt;/td&gt;
&lt;td&gt;752 (95 %)&lt;/td&gt;
&lt;td&gt;19&lt;/td&gt;
&lt;td&gt;6,000&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;* The video run saved a frame every 2,000 steps, the sweep runs every 1,000, so its first piece came somewhere after step 12,000 and by 14,000.&lt;/p&gt;

&lt;p&gt;The short test compared the two settings at step 12,000, 9,000 steps past the warm-up: five pieces off at 0.6, none off at 0.65. Runs with its seed did not repeat it. The budding video ran at 0.6 on the same cloud machine as the test, from the same sheet with the same seed, and still had no piece off at step 12,000. So the test cannot be redone from its seed. In our reruns the first pieces at 0.65 and at 0.6 all came between steps 11,000 and 14,000, and no seed shows 0.6 going first: with the other seed, 0.65 went first.&lt;/p&gt;

&lt;p&gt;Counting lipids instead of pieces tells 0.65 from 0.6. The test is known only from a note in our list of runs. At 0.6 it also followed the share of teal in the sheet, which fell from 20 % to 11 % by step 24,000; for 0.65 it records only "none off at 12000". The reruns counted lipids at both settings. At step 12,000, 9.0 % of the teal was off the sheet at 0.65 against 23 % at 0.6 with the test's seed, and 16 % against 40 % with the other seed. At 0.65 those 9 % were 71 lipids, alone or in groups of fewer than 20, so a count of pieces sees none of them.&lt;/p&gt;

&lt;p&gt;The lines in the chart wobble because a loose piece that drifts back against the sheet counts as part of it again until it leaves once more. At 0.5 the sheet also began to tear: by step 30,000, 6.6 % of the floor plan had no membrane over it. At every other pull it stayed at 0.4 % or below.&lt;/p&gt;

&lt;h2&gt;
  
  
  What counts as "left the sheet"
&lt;/h2&gt;

&lt;p&gt;The chart needs a rule for when a lipid has left, and the rule is a choice. This is the part of the measuring script that makes it:&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;# two lipids touch when any of their tail beads are within 1.5 sigma (periodic box)&lt;/span&gt;
&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cKDTree&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;boxsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;L&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query_pairs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'ndarray'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;coo_matrix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ones&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&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="n"&gt;lipid&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;p&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;0&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;lipid&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;p&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;1&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="n"&gt;shape&lt;/span&gt;&lt;span class="o"&gt;=&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;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;nc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lab&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;connected_components&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="n"&gt;directed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bincount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lab&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;big&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;argmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;# the largest cluster is the sheet&lt;/span&gt;
&lt;span class="n"&gt;inbig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lab&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;big&lt;/span&gt;
&lt;span class="n"&gt;teal_out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isB&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;inbig&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&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="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isB&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&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;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# share of all teal lipids not in the sheet&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tails, not heads, because tails are what hold a double layer together: the heads of the two layers face away from each other and never touch. 1.5σ is a little more than the 1.1σ the lipids start apart, so neighbours in the sheet always count as touching, and a lipid has to be clear of every tail of the sheet to count as gone. A piece is a cluster of 20 or more lipids; smaller groups and single lipids are counted on their own.&lt;/p&gt;

&lt;h2&gt;
  
  
  The first to leave went alone or in small groups
&lt;/h2&gt;

&lt;p&gt;With that rule in place, the agents looked at who left first: single lipids and small groups, not pieces. Two thousand steps after the warm-up (step 5,000), no teal lipid in any run sat in a piece of 20 or more. At 0.7, all 27 teal lipids that had left were alone. At 0.65 it was 51 lipids (32 alone, 19 in groups of two to nineteen) and 48 with the other seed (35 and 13); at 0.6, 84 (47 and 37); at 0.5, 141 (48 and 93). At 0.8, 14 teal lipids were off the sheet at the end, every one of them alone, and no piece formed in the whole run.&lt;/p&gt;

&lt;p&gt;The orange lipids barely moved off: at most 3 of the 3,083 were off the sheet in any frame of any run, the same as in the control. That fits the one difference between the kinds. A teal lipid surrounded by orange neighbours is held by the weaker pull, and the heat bath kicks it out now and then. An orange lipid among orange, or a teal lipid inside a teal patch, is held at full strength.&lt;/p&gt;

&lt;p&gt;Pieces came later, and they did come off the sheet as clumps. For each piece the first time it appeared, the agents looked 1,000 steps back: 78 to 100 % of its lipids had been in the sheet then, depending on the run. Yet only 21 to 62 % of those lipids had never been off the sheet before. The rest had left once, alone or in a piece, and come back. In the 100,000 steps of the budding video, a piece of 20+ lipids came away from the sheet 28 times, and 9 pieces were left at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  What these runs leave out
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It has no water and no real units. σ and τ are not mapped here to nanometres or nanoseconds, so "27,000 steps" says nothing about how long a real membrane would take.&lt;/li&gt;
&lt;li&gt;The box is fixed. The sheet spans it, so its area is set by the box, and every lipid that leaves stretches what remains. In the budding video, 5 % of the floor plan had no membrane over it by the end, after 500 teal lipids had gone. A real membrane free to shrink could behave differently.&lt;/li&gt;
&lt;li&gt;One sheet size, one temperature, one mix of 20 % teal, and two seeds only at 0.65 and 0.6, where the seeds differed by 5 and 2 percentage points.&lt;/li&gt;
&lt;li&gt;Each sweep run is 27,000 steps past its warm-up, and by the lesson of this post that is a short test too. At 0.8 no piece formed in that time, the same kind of "none so far" that the short test saw at 0.65 after 9,000 steps. A longer run at 0.8 could still throw pieces off.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The question it left us with
&lt;/h2&gt;

&lt;p&gt;The sweep found no line where we expected one, between 0.65 and 0.6. Counted in pieces, the grid does show a jump, between 0.8 and 0.7: no piece and 1.8 % of the teal lost, all of it single lipids, at 0.8, against 2 pieces and 23 % at 0.7. We ran no setting between those two, so the grid cannot say what happens there. Maybe the threshold is still there, under the leak of single lipids. Lipowsky's picture says a patch has to grow past a size before it buds, and in a box 48σ across, with a fixed area and teal lipids leaking out one at a time, a patch may never get the chance to grow that large. A bigger box, a sheet held at a fixed tension instead of a fixed area, or the same sweep at a lower and a higher temperature could each tell those apart, and we have run none of them yet.&lt;/p&gt;

&lt;p&gt;Our other science runs are written up on &lt;a href="https://allkeep.org/en/lab" rel="noopener noreferrer"&gt;AllKeep Lab&lt;/a&gt;. If you have simulated mixed membranes, how do you tell a patch that buds off from lipids that leak out one at a time, and did you hold the sheet's tension fixed or its area?&lt;/p&gt;

</description>
      <category>programming</category>
      <category>ai</category>
      <category>science</category>
      <category>simulation</category>
    </item>
    <item>
      <title>API credit would have fixed one of the four faults behind my AI agents' "Try it free" button</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Sun, 22 Nov 2026 22:51:00 +0000</pubDate>
      <link>https://dev.to/nefayran/api-credit-would-have-fixed-one-of-the-four-faults-behind-my-ai-agents-try-it-free-button-2819</link>
      <guid>https://dev.to/nefayran/api-credit-would-have-fixed-one-of-the-four-faults-behind-my-ai-agents-try-it-free-button-2819</guid>
      <description>&lt;p&gt;Early on 22 November (UTC) an automated check caught the "Try it free" photo button of AllKeep Inventory, a home inventory web app, answering every try that reached it with a 500 (02:50 to 04:14 UTC), because the AI account behind it had run out of credit. Our error tracker had already counted 39 such errors in the week before. Topping the account up would have fixed one of four things wrong with that page. The other three were waiting behind it. A failed call spent the visitor's only free try, a 7.6 MB phone photo was refused before our code ran, and once the AI answered again, one of three answers came back with the category "null".&lt;/p&gt;

&lt;h2&gt;
  
  
  The page
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://inventory.allkeep.org/" rel="noopener noreferrer"&gt;AllKeep Inventory&lt;/a&gt; keeps a list of what you own, room by room and box by box, with photos and values, so there is something to hand an insurer after a fire or a burglary. Its landing page has a "Try it free" button: you take one photo of anything, with no account, and an AI model names the thing, writes a line about it and picks a category. One try per device; after that the page asks you to sign up.&lt;/p&gt;

&lt;p&gt;AllKeep is an experiment. AI coding agents write, test and review it, and I direct them and check what they measure. The fixes below all landed on 22 November, and the numbers come from their logs, test runs and pull requests.&lt;/p&gt;

&lt;p&gt;The flow is short. The page reads the photo into a base64 data URL and POSTs it as JSON to a Next.js route on Vercel. The route checks that this device has not used its try, calls a vision model, and returns a name, a description, a category and tags.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The 500, and what the visitor read
&lt;/h2&gt;

&lt;p&gt;An automated check of the live page saw the try fail at 02:50 UTC on a plain photo of a coffee mug. At 04:13 and 04:14 another photo, 155 KB, got a 500 twice, and the runtime log on Vercel said why:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OpenAI API error: You have no credits remaining. Add credits to continue using the API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The account is prepaid, and that morning every AI call in the product went through it. Our error tracker already knew. Its weekly email, sent the day before, listed this error as the top issue of the week with 39 events.&lt;/p&gt;

&lt;p&gt;What a visitor saw was worse than the 500. The page had two failure screens. A 429 got "That's your free try.", and anything else got a screen that told the visitor to try a different photo. So a person who came to see what the app does was told their photo was the problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. A failed call spent the only free try
&lt;/h2&gt;

&lt;p&gt;The route takes the try first and calls the model second, so no paid call runs without a try on record. But nothing gave the try back when the call failed. The row in the &lt;code&gt;anon_attempt&lt;/code&gt; table stayed at &lt;code&gt;attemptCount: 1&lt;/code&gt;, and the visitor who met the outage got "That's your free try" on their next photo.&lt;/p&gt;

&lt;p&gt;The fix releases the reservation when the model call throws, and only then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;result&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createRoutedAIProvider&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;analyzeImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;imageUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;imageBase64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;language&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;analysisType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"full"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// No workspace yet, so empty lists let the provider fill in its defaults.&lt;/span&gt;
    &lt;span class="n"&gt;userContext&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;categories&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="n"&gt;tags&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="n"&gt;currency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"USD"&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;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&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;await&lt;/span&gt; &lt;span class="n"&gt;prisma&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;anonAttempt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;deviceId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attemptCount&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="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;attemptCount&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="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;throw&lt;/span&gt; &lt;span class="n"&gt;error&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;An AI failure now answers 503 with the code &lt;code&gt;AI_SERVICE_ERROR&lt;/code&gt; instead of a 500, and the page has a third screen for any 5xx: "Our AI can't read photos right now", then "your photo is fine", with buttons to create a free account or try again. The OpenAI text goes to the log and the error tracker only.&lt;/p&gt;

&lt;p&gt;One smaller thing came out of the code review. After a good answer the route saves the label on the same row, so it can create the item without a second model call once the visitor signs up. If that write failed, the whole request answered 500, which threw away a result the visitor had already paid for with their try. That write is now best effort: logged, and the 200 goes out anyway.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. A phone photo bigger than the request limit
&lt;/h2&gt;

&lt;p&gt;Even with credit, a big photo straight from a phone camera would still have failed. A 7.6 MB phone photo got this from Vercel before the route ran at all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;413 FUNCTION_PAYLOAD_TOO_LARGE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://vercel.com/docs/errors/FUNCTION_PAYLOAD_TOO_LARGE" rel="noopener noreferrer"&gt;Vercel's functions take a request body of at most 4.5 MB by default&lt;/a&gt;, with a 20 MiB limit as an opt-in beta. The page sent the original file as a base64 data URL inside JSON, and base64 writes every 3 bytes as 4 characters. So the 7.6 MB file became a body of about 10.1 MB, and any file over about 3.4 MB was going to be refused, whatever the model's account held. None of the 11 AI fixture photos in the repo is over 330 KB, so nothing in our tests came near the limit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv00lk54zdc4f1pegwnkq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv00lk54zdc4f1pegwnkq.png" alt="The 7.6 MB photo sent as base64 is about 10.1 MB, more than twice Vercel's 4.5 MB request limit; downsized to a 1600 px JPEG it is a 0.28 MB request" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The page could have opted in to the bigger limit. Shrinking the photo in the browser instead also cuts what a phone uploads, from about 10.1 MB to 0.28 MB, so the fix makes the browser do the shrinking. The page draws the photo onto a canvas at most 1600 px on its long side and sends that as a JPEG:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;MAX_SIDE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1600&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;JPEG_QUALITY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.85&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&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;photoForAnalysis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&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;try&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;bitmap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;createImageBitmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;imageOrientation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"from-image"&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;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fitWithin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bitmap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bitmap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&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;canvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"canvas"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;height&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;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"2d"&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="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&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="s2"&gt;"No 2D canvas"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fillStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"#fff"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillRect&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;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drawImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bitmap&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;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&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;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toDataURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"image/jpeg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;JPEG_QUALITY&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;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;bitmap&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="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;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fileToDataUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In headless Chrome the 7.6 MB photo went out as 1200x1600 in a 278 KB request. The 155 KB photo, already small at 768x1024, went out at its own size in a 175 KB request.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;imageOrientation: "from-image"&lt;/code&gt; applies the photo's EXIF rotation, so a portrait photo is drawn upright. The white fill came from the code review: the first version turned the transparent parts of PNG and WebP files black. A file the browser cannot draw is sent as it is.&lt;/p&gt;

&lt;p&gt;The server got its own limit too: the route refuses a base64 string over 4 MiB, a little under Vercel's 4.5 MB.&lt;/p&gt;

&lt;p&gt;One case is left. A HEIC file over about 3 MB, in a browser that can't draw HEIC, still goes as it is and still fails on size. The screen it gets says "try a different photo", which for that case is the right advice.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. When it worked, the category said "null"
&lt;/h2&gt;

&lt;p&gt;At 21:35 UTC, from a fresh IP, the coffee-mug photo answered 200 in 3.3 seconds (the page tells the visitor to expect about 8 to 14 seconds): "Ceramic Coffee Mug", a description, the category "Kitchen &amp;amp; Dining". A second try from the same device answered 429, as it should. A forced 503 on the live page showed the new "your photo is fine" screen.&lt;/p&gt;

&lt;p&gt;In the same check, one of three calls came back with &lt;code&gt;"category": "null"&lt;/code&gt;, and the page printed it: &lt;strong&gt;CATEGORY null&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The prompt has placeholders for the user's own categories, tags and currency. This is where they are filled in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;userContext&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;categories&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;categoriesList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;userContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;categories&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;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
      &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;formatCategoriesForPrompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;userContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;getDefaultCategoriesString&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;promptText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;promptText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{CATEGORIES}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;categoriesList&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 fallback to the default list is there, but it sits inside the &lt;code&gt;if&lt;/code&gt;. A signed-in user always has a context, so their prompt was always filled in. The anonymous route has no user and passed no context at all, so the whole block was skipped, and the same happened to &lt;code&gt;{TAGS}&lt;/code&gt; and &lt;code&gt;{CURRENCY}&lt;/code&gt;. The model was asked to pick a category from the literal text &lt;code&gt;{CATEGORIES}&lt;/code&gt;, and sometimes it answered with the word "null".&lt;/p&gt;

&lt;p&gt;The fix is two lines and a filter. The route passes an empty context (empty lists, USD), which sends the provider down the default-list path it already had; that is the &lt;code&gt;userContext&lt;/code&gt; line in the snippet in section 2. And a category that comes back empty or as "null", "none", "undefined" or "n/a" is dropped, so the page hides the row instead of printing the word. Seven of the 24 tests in the route and provider suites failed against the main branch; with the change, those 24 and the router's four, 28 in all, pass. The live check that posts the mug photo to production now also fails when the description or a real category is missing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hole the outage made us look at
&lt;/h2&gt;

&lt;p&gt;While reading the route we looked at what "one try per device" means. The device is a UUID that the page makes itself and sends in a header. A new UUID is a new device, so anyone with a loop could make a paid vision call per request until the prepaid account was empty, the same state that caused the outage.&lt;/p&gt;

&lt;p&gt;The route now holds three limits before it calls the model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;one IP address gets at most 3 tries a day, read from &lt;code&gt;x-real-ip&lt;/code&gt;. &lt;a href="https://vercel.com/docs/headers/request-headers" rel="noopener noreferrer"&gt;Vercel sets that header itself&lt;/a&gt; and overwrites any forwarded address a client sends, "to prevent IP spoofing", so a client cannot forge it there;&lt;/li&gt;
&lt;li&gt;all anonymous tries together stop at a fixed number a day, set in &lt;code&gt;ANON_AI_DAILY_CAP&lt;/code&gt;; over that the route answers 503 and the page shows the "can't read photos right now" screen;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ANON_AI_OFF=1&lt;/code&gt; turns the route off with a redeploy and no code change.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Three new tests fail against the old route and pass now.&lt;/p&gt;

&lt;h2&gt;
  
  
  A second provider behind the first
&lt;/h2&gt;

&lt;p&gt;The outage also showed that one empty account stops the product's first step. Later that day the agents added a Gemini provider beside OpenAI, reusing the same prompts and the same parsing of the answer, and a small router that tries the provider named in &lt;code&gt;AI_PROVIDER&lt;/code&gt; and hands the same request to the other one when the first fails on its own side.&lt;/p&gt;

&lt;p&gt;This is where the router decides what counts as "its own side":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;switchable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&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;error&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;AppError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// the provider's own trouble; a validation error is the request's and goes back to the caller&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"AI_SERVICE_ERROR"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;statusCode&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="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
      &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
      &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;402&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="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// a network error, a timeout, an unexpected response&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quota and credit answers from either side (HTTP 429 and 402, Gemini's &lt;code&gt;RESOURCE_EXHAUSTED&lt;/code&gt;, OpenAI's &lt;code&gt;insufficient_quota&lt;/code&gt; and "no credits remaining") are marked as one error type and never retried on the same provider. A bad request goes back to the caller, because the other provider would refuse it too. Unit tests mock both providers' HTTP, including a bad-key 400 that must not count as quota.&lt;/p&gt;

&lt;p&gt;The first model the agents wired in was &lt;code&gt;gemini-2.5-flash&lt;/code&gt;, which Google had already deprecated: it is gone from AI Studio, and from 1 December 2026 its API requests go to another model (&lt;a href="https://ai.google.dev/gemini-api/docs/deprecations" rel="noopener noreferrer"&gt;Gemini deprecations&lt;/a&gt;). Our new key could not call it at all; the API answered that the model is "no longer available to new users". The key worked on &lt;code&gt;gemini-3-flash-preview&lt;/code&gt;, a preview model that the same page already lists with &lt;code&gt;gemini-3.6-flash&lt;/code&gt; as its replacement. So the model name now comes from &lt;code&gt;GEMINI_MODEL&lt;/code&gt;, and the next swap needs no code change, only a redeploy.&lt;/p&gt;

&lt;p&gt;The check at 21:35 UTC in section 4 ran after the router was merged and did not record which provider answered, so I can't say whether the OpenAI account had credit again by then.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I still don't know
&lt;/h2&gt;

&lt;p&gt;I have no count yet of how often the model returns no category after the merge, against one of three "null" answers before it.&lt;/p&gt;

&lt;p&gt;I also don't know how best to limit a free AI call for people with no account. Our device id is made by the client, so it limits nothing on its own. The IP limit is the only one the client does not make up itself, and it is crude, because a mobile network or an office can put many people behind one address, so the fourth visitor of the day from there gets "That's your free try." without having tried. The daily cap only limits the total.&lt;/p&gt;

&lt;p&gt;You can try the photo yourself on the &lt;a href="https://inventory.allkeep.org/" rel="noopener noreferrer"&gt;AllKeep Inventory page&lt;/a&gt; with the "Try it free" button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you run a free, no-sign-up AI call on a public page, what do you limit it by (a captcha before the call, a signed token from the page, proof of work, a cap per IP, something else), and how many ordinary visitors did it turn away when you changed it?&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>nextjs</category>
      <category>vercel</category>
    </item>
    <item>
      <title>My AI agents' Godot game drew trees and a town behind its planet; two fixes cut 3 ms of GPU time</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Sun, 22 Nov 2026 22:28:38 +0000</pubDate>
      <link>https://dev.to/nefayran/my-ai-agents-godot-game-drew-trees-and-a-town-behind-its-planet-two-fixes-cut-3-ms-of-gpu-time-1a0k</link>
      <guid>https://dev.to/nefayran/my-ai-agents-godot-game-drew-trees-and-a-town-behind-its-planet-two-fixes-cut-3-ms-of-gpu-time-1a0k</guid>
      <description>&lt;p&gt;At the starting camp of our game, trees cost 4.0 to 4.4 ms of every frame, and part of that went to trees nobody could see: they stood on the far side of the planet. Two fixes, smaller pieces of trees and a test that skips whatever is behind the horizon, cut the GPU part of the frame by 3.0 to 3.5 ms in each of three test runs, but the full frame got faster by more than half a millisecond only in run 3 (2.4 ms at 120 m, 3.1 ms at 64 m).&lt;/p&gt;

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

&lt;p&gt;The game is &lt;a href="https://allkeep.org/en/products" rel="noopener noreferrer"&gt;Planet Wanderer&lt;/a&gt;, and it is an experiment: AI coding agents write it in Godot 4, and I direct them, play the builds and check what they measure. A small rover drives around a planet built from hexagonal cells. The planet is a sphere with a radius of 380 m, small enough that the world curves away visibly.&lt;/p&gt;

&lt;p&gt;The numbers below come from the game's own benchmark on one Windows laptop: an RTX 4060 Laptop GPU, Godot 4.7.2 with the Compatibility renderer (OpenGL 3.3), 1920x1080, VSync off, frame rate capped at 60 per second (none of the means below reached the cap). The benchmark drives the camera to a fixed spot beside the starting camp, turns one kind of object on or off, and logs the frame time and the GPU time of each variant twice, alternating: the new variant, the old one, the new one again, the old one again.&lt;/p&gt;

&lt;p&gt;We were looking for where the camp's frame time went. Trees stood out: 4.0 to 4.4 ms per frame. Of that, 3.4 ms came from the &lt;em&gt;far&lt;/em&gt; level of detail, the cheap version of a tree that is used when it is distant, which made it the first suspect.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trees were drawing behind the planet
&lt;/h2&gt;

&lt;p&gt;The far level of detail was set to draw trees up to 900 m from the eye. The planet's radius is 380 m. From the camp, the horizon is much closer than 900 m, and everything past it is hidden by the ground. The trees were culled by the camera's view and by that distance, and the forests on the planet's back side passed both. So the game sent them to the GPU, the GPU drew them, and the depth test threw them away pixel by pixel.&lt;/p&gt;

&lt;p&gt;The same was true of the town. A settlement of six cells stands 600 to 680 m from the camp, on the other side of the planet. It cost 0.7 to 0.8 ms per frame while being completely invisible.&lt;/p&gt;

&lt;p&gt;Godot has its own answer to this: occlusion culling with a sphere occluder (&lt;code&gt;OccluderInstance3D&lt;/code&gt; with a &lt;code&gt;SphereOccluder3D&lt;/code&gt;). The benchmark tried it on 14 November, on an earlier build that still had the old 180 m tree pieces, with a sphere the size of the planet's lowest ground. At 120 m from the camp, the occluder and an early version of the horizon test described below each left 6.24 of 6.86 million triangles drawn, and the GPU times were close: 18.0 and 18.7 ms for the occluder, 17.3 and 18.8 ms for the horizon test.&lt;/p&gt;

&lt;p&gt;The game kept its own test because of what the engine's occluder had done to the ground earlier. The planet's land pieces already skipped themselves behind the horizon with this test, after a sphere occluder 3 m under the sea left holes along the tiles' edges near the camera, and a sphere 20 m under the sea did the same. The engine takes the box's point nearest the eye by distance, and for a 64 m piece of land right beside the camera that point does not have the box's smallest depth along the view. So the trees and the town went onto the test the land already used.&lt;/p&gt;

&lt;p&gt;Two changes fixed this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Far-level trees are now laid out in pieces of 60 m instead of 180 m. A piece is drawn or skipped as a whole, so smaller pieces mean fewer trees survive when only a corner of a piece is in view. With the old pieces, the far level could be drawn up to 157 m past its intended range. A new test checks that it never goes further past its range than the near level does (52 m).&lt;/li&gt;
&lt;li&gt;Every settlement cell and every piece of trees is tested against the planet's horizon, and skipped when it is hidden.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The horizon test
&lt;/h2&gt;

&lt;p&gt;The test is the horizon culling point from a &lt;a href="https://cesium.com/blog/2013/05/09/computing-the-horizon-occlusion-point/" rel="noopener noreferrer"&gt;Cesium article on horizon culling&lt;/a&gt;. What a sphere hides from an eye is a convex region. If all eight corners of a bounding box are hidden, the whole box is hidden. So the game computes one point per box once, and each frame checks only that point.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="c1"&gt;# For a box around a cell: one point that is hidden exactly when the whole box is.&lt;/span&gt;
&lt;span class="c1"&gt;# Returns ZERO when the box is too wide to have one (then it is always drawn).&lt;/span&gt;
&lt;span class="n"&gt;static&lt;/span&gt; &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;horizon_point&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;AABB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r_occ&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_center&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;normalized&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="mf"&gt;0.0&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="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_endpoint&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="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;r_occ&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mag2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;maxf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;length_squared&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="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mag2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalized&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;cos_a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sin_a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cross&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;cos_b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;mag&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sin_b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mag2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;cos_b&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;den&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cos_a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;cos_b&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;sin_a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;sin_b&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;den&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mf"&gt;1e-6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ZERO&lt;/span&gt;
        &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;maxf&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="mf"&gt;1.0&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;den&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;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;


&lt;span class="c1"&gt;# Is the point p behind the unit sphere as seen from the eye at cv?&lt;/span&gt;
&lt;span class="c1"&gt;# vh2 is |cv|^2 - 1, the squared distance from the eye to the sphere's limb.&lt;/span&gt;
&lt;span class="n"&gt;static&lt;/span&gt; &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vh2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;vt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;cv&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;vt_vc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;vt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cv&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;vt_vc&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;vh2&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;vt_vc&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;vt_vc&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;vt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;length_squared&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="n"&gt;vh2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;r_occ&lt;/code&gt; is the radius of a sphere 8 m under the sea, 372 m against the planet's 380 m: a line of sight lower than that runs through the ground, or through water at a grazing angle, which shows nothing. Everything is divided by &lt;code&gt;r_occ&lt;/code&gt;, so that sphere becomes the unit sphere. &lt;code&gt;horizon_point&lt;/code&gt; runs once per box when the world loads. &lt;code&gt;hidden&lt;/code&gt; costs a dot product and a few multiplications, and the game tests a quarter of the list each frame, so each box is checked every fourth frame; the 8 m margin covers the frames in between.&lt;/p&gt;

&lt;p&gt;The box for a settlement cell is its hexagon made a third wider, from 2 m under its ground to 40 m above it. It is sized this way on purpose. The settlement's buildings grow as the game goes on, so a box built from the current geometry would be too small a few stages later.&lt;/p&gt;

&lt;p&gt;The test for it checks that the box contains the ground point, the point 40 m above it and the hexagon's corners, that the cell is not hidden when seen from above it, and that it is hidden from the opposite side of the planet. The not-hidden check is there because a horizon test that hides too much looks fine in a benchmark and shows up later as a hole in the world.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug the benchmark did not show
&lt;/h2&gt;

&lt;p&gt;The first version hid the town's cells from the moment the player landed. Its frame time was the same as the final version's. But after a landing, the town had no footpaths and no trampled grass.&lt;/p&gt;

&lt;p&gt;The game reads the ground under each settlement cell, to paint paths and worn grass, from the meshes that are &lt;em&gt;visible&lt;/em&gt;. A cell hidden behind the planet had no visible mesh, so nothing was read. The fix is an ordering one: cells go on the horizon list only after the ground-reading step has run for them. The frame time did not change, and the town got its paths back.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three runs, one build
&lt;/h2&gt;

&lt;p&gt;The benchmark ran three times on 15 November within about an hour, on the same laptop and the same build. Each cell below is the mean of the two repeats inside one run.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd7nizoicoq81tquvojho.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd7nizoicoq81tquvojho.png" alt="Same build, same laptop, three runs: GPU time fell by about 3 ms in each run, at 120 m the full frame got faster only in run 3" width="800" height="352"&gt;&lt;/a&gt;&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;Camera from the camp&lt;/th&gt;
&lt;th&gt;GPU before&lt;/th&gt;
&lt;th&gt;GPU after&lt;/th&gt;
&lt;th&gt;Frame before&lt;/th&gt;
&lt;th&gt;Frame after&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;120 m&lt;/td&gt;
&lt;td&gt;17.9 ms&lt;/td&gt;
&lt;td&gt;14.5 ms&lt;/td&gt;
&lt;td&gt;23.7 ms&lt;/td&gt;
&lt;td&gt;25.2 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;64 m&lt;/td&gt;
&lt;td&gt;20.3 ms&lt;/td&gt;
&lt;td&gt;16.8 ms&lt;/td&gt;
&lt;td&gt;21.6 ms&lt;/td&gt;
&lt;td&gt;21.7 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;120 m&lt;/td&gt;
&lt;td&gt;17.9 ms&lt;/td&gt;
&lt;td&gt;14.6 ms&lt;/td&gt;
&lt;td&gt;23.2 ms&lt;/td&gt;
&lt;td&gt;25.8 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;64 m&lt;/td&gt;
&lt;td&gt;18.4 ms&lt;/td&gt;
&lt;td&gt;15.3 ms&lt;/td&gt;
&lt;td&gt;24.4 ms&lt;/td&gt;
&lt;td&gt;23.9 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;120 m&lt;/td&gt;
&lt;td&gt;20.1 ms&lt;/td&gt;
&lt;td&gt;17.0 ms&lt;/td&gt;
&lt;td&gt;20.9 ms&lt;/td&gt;
&lt;td&gt;18.5 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;64 m&lt;/td&gt;
&lt;td&gt;21.3 ms&lt;/td&gt;
&lt;td&gt;18.4 ms&lt;/td&gt;
&lt;td&gt;22.1 ms&lt;/td&gt;
&lt;td&gt;19.0 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The two changes together saved 3.0 to 3.5 ms of GPU time in every run and at both distances. At 120 m the scene went from 6.86 to 5.76 million triangles and from about 2,620 to 2,480 draw calls.&lt;/p&gt;

&lt;p&gt;Run 1 also measured the smaller pieces without the horizon test. At 120 m the pieces alone moved the GPU time from 17.9 to 17.7 ms and raised the draw calls from about 2,620 to 3,270; the horizon test then brought them to 14.5 ms and 2,477 draw calls, 3.25 ms of the saving. At 64 m the pieces alone gave 20.3 to 19.2 ms, and the horizon test 16.8 ms.&lt;/p&gt;

&lt;p&gt;In runs 1 and 2 the full frame sat up to 11.2 ms above the GPU time. At 64 m the frame changed by less than half a millisecond (21.6 to 21.7 ms, 24.4 to 23.9 ms). At 120 m the mean got 1.5 ms longer in run 1 and 2.6 ms longer in run 2, all of it in one measurement: the new variant's first repeat at 120 m, which is also the first measurement of each run. It took 27.2 and 28.5 ms, against 23.2 and 23.0 ms for the new variant's second repeat. In run 3 the frame sat less than a millisecond above the GPU time before the change, and it followed the GPU down: 20.9 to 18.5 ms at 120 m, 22.1 to 19.0 ms at 64 m, which is 48 to 54 and 45 to 53 frames per second.&lt;/p&gt;

&lt;p&gt;Run 3 is also the only one that logged the CPU's rendering time. It fell from 9.4 to 8.5 ms at 120 m and from 9.5 to 8.5 ms at 64 m, while the draw calls at 120 m went from about 2,620 to 2,480. My guess is that fewer pieces drawn cost the CPU less to submit, but nothing in the log separates that out.&lt;/p&gt;

&lt;p&gt;Frames from before and after were compared pixel by pixel: at most 60 pixels out of about two million differed, and none by more than 12 out of 255 levels.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I still don't know
&lt;/h2&gt;

&lt;p&gt;The same build, on the same laptop, an hour apart, gave a GPU time of 17.9 ms in one run and 20.1 ms in another, and a frame time of 23.7 ms in one and 20.9 ms in another. Inside each of the three runs of 15 November the GPU repeats agree within about 0.75 ms, so the spread comes from one run to the next (the 14 November run was looser: 17.3 and 18.8 ms for the same variant). The frame repeats agree less, and the two slow ones were each the first measurement of their run, which is why a warm-up pass is the first thing I would try.&lt;/p&gt;

&lt;p&gt;In runs 1 and 2 the frame was waiting on something that was not the GPU, and those two runs did not log the CPU side, so I can't say what it was. My guesses are the laptop's power and clock states, which the benchmark does not record, or the driver queueing frames under the Compatibility renderer. Neither is measured.&lt;/p&gt;

&lt;p&gt;There are no Mac numbers in this article. On the Mac the GPU time reads as 0 in the game's log, so only full frames could be compared there.&lt;/p&gt;

&lt;p&gt;So here is the question I'd like an answer to: &lt;strong&gt;on a laptop GPU, how do you make a Godot 4 frame-time benchmark repeat between runs, so that a 3 ms GPU saving shows up in the frame every time and not once in three?&lt;/strong&gt; Pinning clocks, a warm-up pass, more repeats, a different renderer: if you have tried one of these on a similar scene, I would like to hear what moved the spread.&lt;/p&gt;

&lt;p&gt;Planet Wanderer has no release yet. Its page, with the other things my agents build and measure, is at &lt;a href="https://allkeep.org/en/products" rel="noopener noreferrer"&gt;allkeep.org/en/products&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>performance</category>
      <category>godot</category>
      <category>gdscript</category>
    </item>
    <item>
      <title>I orbited my game's camera and 1,366 grass pixels popped every step; measuring from the pivot made it 0</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Wed, 18 Nov 2026 13:04:42 +0000</pubDate>
      <link>https://dev.to/nefayran/i-orbited-my-games-camera-and-1366-grass-pixels-popped-every-step-measuring-from-the-pivot-made-1glb</link>
      <guid>https://dev.to/nefayran/i-orbited-my-games-camera-and-1366-grass-pixels-popped-every-step-measuring-from-the-pivot-made-1glb</guid>
      <description>&lt;p&gt;When the camera in my Godot 4 game circled the rover, about 1,366 pixels of grass changed brightness from one step to the next. Nothing moved. Nothing was added. The pixels were plants switching to a cheaper or richer version of themselves. After I changed what "distance" means in the level-of-detail code, the same orbit gave 0 popping pixels in six of six positions. The first version of that fix showed no change at all, and the reason was a bug in my measurement, not in the fix.&lt;/p&gt;

&lt;p&gt;Below: how I counted popping pixels without eyeballing a video, the shader change (a few lines), the second source of popping that the shader change did not touch, and one question I still cannot answer.&lt;/p&gt;

&lt;p&gt;The game is a Godot 4 project where a small rover explores a hex-tile planet covered in meadow: millions of blades, tufts and flowers drawn as instanced meshes. Numbers are from my own test runs on one Windows PC.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was wrong
&lt;/h2&gt;

&lt;p&gt;Level of detail (LOD) means a far plant is drawn simpler than a near one. My meadow has several levels per kind of plant, for example "carpet" blades at 0-70 m, 70-180 m and 180-330 m, tufts at 0-85 m and beyond, flowers at 0-130 m and beyond. Each plant picks its level from its distance to the camera's eye.&lt;/p&gt;

&lt;p&gt;That is the standard setup, and it is fine while the camera moves forward. It is not fine when the camera turns around the player. The game's view circles a point above the rover. A plant 100 m from the rover can be 84 m from the eye at one end of the turn and 166 m at the other. On the way it crosses every level boundary between those two numbers. The plant itself never moved. So the grass shimmered on every orbit, and the shimmer was worst on the flowers, which are small bright dots.&lt;/p&gt;

&lt;p&gt;I could see it. I could not say how much, or whether a fix helped. "Looks calmer" is not a measurement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Counting pops
&lt;/h2&gt;

&lt;p&gt;The test renders each step of an orbit twice with time stopped:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;frame A: plants have the levels the previous camera position gave them;&lt;/li&gt;
&lt;li&gt;frame B: plants have the levels the current position gives them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same camera, same lighting, same pixels, so any pixel that differs by more than 8 out of 255 in luma is a pop. To say which level change caused it, I render a third and fourth copy where every plant is painted flat with a colour for its level, plus a black one, and read each popping pixel's level before and after from those.&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;# tools/orbit_pops.py (trimmed)&lt;/span&gt;
&lt;span class="n"&gt;pop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;luma&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;luma&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;B&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="mi"&gt;8&lt;/span&gt;        &lt;span class="c1"&gt;# pixels that changed between steps&lt;/span&gt;
&lt;span class="n"&gt;la&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;levels&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;paint_A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;paint_black&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;# level index per pixel, -1 = no plant&lt;/span&gt;
&lt;span class="n"&gt;lb&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;levels&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;paint_B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;paint_black&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;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;la&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lb&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pop&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;kinds&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;"{NAMES[a]} -&amp;gt; {NAMES[b]}"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On six positions of the orbit around the 120 m view, with levels chosen by the eye's distance:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Position&lt;/th&gt;
&lt;th&gt;Popping pixels&lt;/th&gt;
&lt;th&gt;Plant pixels&lt;/th&gt;
&lt;th&gt;Share&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2,385&lt;/td&gt;
&lt;td&gt;457,502&lt;/td&gt;
&lt;td&gt;0.52 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;913&lt;/td&gt;
&lt;td&gt;608,702&lt;/td&gt;
&lt;td&gt;0.15 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1,200&lt;/td&gt;
&lt;td&gt;611,786&lt;/td&gt;
&lt;td&gt;0.20 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;1,537&lt;/td&gt;
&lt;td&gt;500,263&lt;/td&gt;
&lt;td&gt;0.31 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;1,303&lt;/td&gt;
&lt;td&gt;475,910&lt;/td&gt;
&lt;td&gt;0.27 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;856&lt;/td&gt;
&lt;td&gt;425,950&lt;/td&gt;
&lt;td&gt;0.20 %&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Total&lt;/td&gt;
&lt;td&gt;8,194&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;1,366 a step&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Under half a percent of the plant pixels, but they are the bright ones, and the eye is built to notice a dot that blinks.&lt;/p&gt;

&lt;p&gt;One detail I did not expect: of the 8,194 pops, 3,271 went from a level to the same level. The largest single kind was "flowers 0-130 to flowers 0-130" with 2,264. My reading, which I did not verify: those are plants in the middle of a cross-fade, where the level is the same but the fade amount changed with distance. The fix below removed them too, so the cause is the distance, whichever way it acts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: measure from the pivot
&lt;/h2&gt;

&lt;p&gt;The orbit keeps one thing constant: the distance between the eye and the point it turns around. So I stopped using the eye's distance to the plant and used this instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight glsl"&gt;&lt;code&gt;&lt;span class="c1"&gt;// meadow_plant.gdshader (trimmed)&lt;/span&gt;
&lt;span class="n"&gt;global&lt;/span&gt; &lt;span class="n"&gt;uniform&lt;/span&gt; &lt;span class="n"&gt;vec4&lt;/span&gt; &lt;span class="n"&gt;lod_focus&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// xyz: the point the camera turns round, w: eye-to-point distance&lt;/span&gt;

&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;dl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;distance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CAMERA_POSITION_WORLD&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          &lt;span class="c1"&gt;// before&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;lod_focus&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;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;vec3&lt;/span&gt; &lt;span class="n"&gt;fo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;lod_focus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;xyz&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;dl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;dot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;lod_focus&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;lod_focus&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="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// after&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The plant's distance is now the hypotenuse of two legs: plant to pivot, and pivot to eye. When the camera orbits, both legs stay the same, so &lt;code&gt;dl&lt;/code&gt; stays the same, so no plant changes level. When the camera does not orbit (a cutscene camera with &lt;code&gt;w = 0&lt;/code&gt;), the code falls back to the eye's distance as before.&lt;/p&gt;

&lt;p&gt;The game's camera writes the uniform once a frame:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="n"&gt;lod_focus_v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Vector4&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;look&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;look&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;look&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;orbit_cam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;global_position&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;distance_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;look&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nc"&gt;RenderingServer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;global_shader_parameter_set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"lod_focus"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lod_focus_v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The shader gets one extra square root per plant, which I did not measure separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix that measured nothing
&lt;/h2&gt;

&lt;p&gt;I ran the test with the new shader. The numbers were identical to the old ones, to the pixel: 8,169 popping pixels with the eye's distance, 8,169 with the focus.&lt;/p&gt;

&lt;p&gt;I did not believe the fix did nothing; the arithmetic is simple. The test script read the focus back from the engine, and the engine returned an empty vector for it, so the "by the focus" run silently fell back to the eye. The comparison was the old code against the old code. After the test took the focus from the game's camera object instead, the same run gave 1 popping pixel in 8,141.&lt;/p&gt;

&lt;p&gt;That is the part I would tell my past self: when a fix changes nothing, check that the test can see the change before you doubt the fix. Identical numbers to the last pixel were the clue. Real noise does not repeat that precisely.&lt;/p&gt;

&lt;h2&gt;
  
  
  The second source: whole pieces
&lt;/h2&gt;

&lt;p&gt;One pixel was not zero, and the shader is not the only thing that decides what is drawn. The meadow is cut into pieces (22,233 of them), and the engine hides a whole piece when its middle is farther from the eye than the piece's visibility range. Those ranges also use the eye. In the same orbit, 2 to 8 pieces switched on or off per step, with up to 1,136 plants inside them that the shader had just decided to draw.&lt;/p&gt;

&lt;p&gt;The engine does not let me give a piece a different measure of distance, so I took the ranges over:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;at load, each piece's visibility range is saved in metadata and set to 0 in the engine;&lt;/li&gt;
&lt;li&gt;each frame a script tests the pieces by the same formula as the shader, with the pivot and the eye distance;&lt;/li&gt;
&lt;li&gt;the pass over 22,233 pieces cost 1.4 to 1.6 ms on my Mac, so a quarter of the pieces are tested per frame, and only once the pivot or the distance has moved by 25 cm.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="n"&gt;static&lt;/span&gt; &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;shows&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Vector3&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="nc"&gt;Vector2&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="nc"&gt;Vector4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;distance_squared_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Vector3&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="n"&gt;x&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="n"&gt;y&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="n"&gt;z&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;m&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;m&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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;&amp;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;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="no"&gt;SLACK&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&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;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;SLACK&lt;/span&gt;   &lt;span class="c1"&gt;# SLACK 4 m hides the quarter-frame lag&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A unit test on 684 pieces laid out as the game lays them, with the eye turned around the pivot at 64 m: by the engine's ranges, 223 pieces changed state and 114 were hidden while plants in them were in range. By the pivot, none.&lt;/p&gt;

&lt;p&gt;Final orbit, six positions out of six: 0 popping pixels, and 0 pieces switching.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I take from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;LOD by the eye's distance assumes the eye only approaches or leaves. A camera that orbits a point breaks that assumption, and the symptom is shimmer you cannot catch in a screenshot.&lt;/li&gt;
&lt;li&gt;Render the same step twice with only the thing under test changed, and diff. It gave me a number I could chase down to zero.&lt;/li&gt;
&lt;li&gt;If a fix shows the same number to the last digit, suspect the harness.&lt;/li&gt;
&lt;li&gt;Every system that decides visibility needs the same measure. The shader and the engine's piece ranges disagreed, and that disagreement was the last pixel and the last 114 pieces.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The part I still do not know
&lt;/h2&gt;

&lt;p&gt;My measure only works for a camera that circles a known point. The game also has a free camera that moves and turns at the same time. For that camera I fall back to the eye, so the grass pops again whenever it turns.&lt;/p&gt;

&lt;p&gt;I could use the point the camera looks at on the ground, but that point jumps when the view crosses a ridge or a tree. I could smooth it over a second, but then the plants near the pivot lag behind the camera. Has anyone found a distance for LOD that is stable under a camera that both orbits and travels? Or do you accept some pops and hide them with a longer cross-fade?&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>performance</category>
      <category>godot</category>
      <category>shaders</category>
    </item>
    <item>
      <title>I cut 121 of 2,093 Godot draw calls and the frame time didn't move</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Mon, 16 Nov 2026 12:31:40 +0000</pubDate>
      <link>https://dev.to/nefayran/i-cut-121-of-2093-godot-draw-calls-and-the-frame-time-didnt-move-564o</link>
      <guid>https://dev.to/nefayran/i-cut-121-of-2093-godot-draw-calls-and-the-frame-time-didnt-move-564o</guid>
      <description>&lt;p&gt;At the end of my game's demo run the median frame took 21.9 ms. After one day of adding long caves and tunnels it took 24.1 ms. I blamed the new underground view, hid it, and the frame stayed at 23.5 to 24.4 ms. Then I removed 121 of its 2,093 draw calls, and the frame time on the test scene stayed where it was. Below are the three measurements, the 40 lines of GDScript that made the draw-call cut, and the explanation I cannot yet prove.&lt;/p&gt;

&lt;p&gt;The game is a Godot 4 project where a small rover digs shafts into a hex-tile planet. The numbers come from the game's own test runs, one Windows PC, same build settings for each pair I compare. I read them from the log line the game prints at the end of a run (frames per second and median frame time).&lt;/p&gt;

&lt;h2&gt;
  
  
  What the "dig view" is
&lt;/h2&gt;

&lt;p&gt;When the rover is down a shaft, the game cuts a cross-section out of the ground around it: the shaft walls, the neighbouring cave, ponds, glowing mushrooms, crystals, grass tufts and loose stones on the cave floor. On 11 November I made caves long (a hundred and fifty winding tunnels per planet instead of single rooms) and let the rover dig sideways. That is a lot of small things on a lot of floors.&lt;/p&gt;

&lt;p&gt;Every mushroom, crystal, tuft and stone was its own &lt;code&gt;MeshInstance3D&lt;/code&gt;. A cave cell with mushrooms had 31 to 42 nodes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measurement 1: the frame got slower
&lt;/h2&gt;

&lt;p&gt;I run the whole level start to finish with a bot, once per playable race, and read the numbers at the end of the demo, when the player has dug the last shaft.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Run (humans)&lt;/th&gt;
&lt;th&gt;FPS at end&lt;/th&gt;
&lt;th&gt;Median frame&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Before the long caves&lt;/td&gt;
&lt;td&gt;44&lt;/td&gt;
&lt;td&gt;21.9 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After the long caves&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;24.1 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The other two races landed in the same place: 40 fps and 23.7 ms, 41 fps and 23.9 ms. So it was not a one-off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measurement 2: hide the suspect
&lt;/h2&gt;

&lt;p&gt;The obvious suspect was the dig view, because it was the new thing. I added a switch to the run that hides the dig view at the end of the demo, in pieces and then as a whole, and read the frame time each time.&lt;/p&gt;

&lt;p&gt;Hidden piece by piece, hidden entirely: 23.5 to 24.4 ms. The same as with it visible. The dig view was not paying for the 2.2 ms, at least not at that moment of the run.&lt;/p&gt;

&lt;p&gt;What had changed there, besides the caves, is that a cave now sits next to the last shaft, and at the end of the demo the camera turns toward it. A different side of the forest and the village comes into frame. A scene that simply contains more things looks the same as a feature that costs more, and a bot that always ends in the same place cannot tell them apart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measurement 3: the cheap fix I could verify
&lt;/h2&gt;

&lt;p&gt;The part I could fix and verify was the node count. Godot draws each &lt;code&gt;MeshInstance3D&lt;/code&gt; as its own draw call. Things that share a mesh and a material can be one &lt;code&gt;MultiMeshInstance3D&lt;/code&gt; with many instances, one draw call for the lot. I had a note from an earlier run that the cave beside the last shaft added about 390 draw calls, roughly 2 ms. That is close enough to the 2.2 ms gap to be worth a try.&lt;/p&gt;

&lt;p&gt;The change is a small collector. Callers say "put this mesh with this material here" and the collector groups by mesh and material, then makes one &lt;code&gt;MultiMeshInstance3D&lt;/code&gt; per group at the end:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;_groups&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="c1"&gt;# key -&amp;gt; {mesh, mat, shadow, xfs: [Transform3D], cols: [Color or null]}&lt;/span&gt;

&lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mesh&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Mesh&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Material&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;xf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Transform3D&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;col&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shadow&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;void&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s2"&gt;"%d/%d/%s"&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;mesh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_instance_id&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;mat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_instance_id&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="s2"&gt;"s"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;shadow&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="s2"&gt;"n"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;_groups&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&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;_groups&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="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"mesh"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mesh&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"mat"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"shadow"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;shadow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"xfs"&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="s2"&gt;"cols"&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="n"&gt;_groups&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="s2"&gt;"xfs"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;_groups&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="s2"&gt;"cols"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;flush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Node3D&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;made&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Array&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;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;_groups&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Dictionary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_groups&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="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;coloured&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cols"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;func&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="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&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;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mm&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nc"&gt;MultiMesh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;mm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;transform_format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MultiMesh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;TRANSFORM_3D&lt;/span&gt;
        &lt;span class="n"&gt;mm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;use_colors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;coloured&lt;/span&gt;          &lt;span class="c1"&gt;# before instance_count, or Godot ignores it&lt;/span&gt;
        &lt;span class="n"&gt;mm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mesh&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"mesh"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;mm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instance_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"xfs"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&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="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"xfs"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&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;mm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_instance_transform&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="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"xfs"&lt;/span&gt;&lt;span class="p"&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;coloured&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;mm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_instance_color&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="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cols"&lt;/span&gt;&lt;span class="p"&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cols"&lt;/span&gt;&lt;span class="p"&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="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;null&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;WHITE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;mi&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nc"&gt;MultiMeshInstance3D&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;mi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;multimesh&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mm&lt;/span&gt;
        &lt;span class="n"&gt;mi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;material_override&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"mat"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;mi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;layers&lt;/span&gt;
        &lt;span class="n"&gt;mi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cast_shadow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;GeometryInstance3D&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SHADOW_CASTING_SETTING_ON&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"shadow"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; \
            &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nc"&gt;GeometryInstance3D&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SHADOW_CASTING_SETTING_OFF&lt;/span&gt;
        &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_child&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;made&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;_groups&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clear&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;made&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(The listing is trimmed from the game's file; the real one is the same shape.) One trap is in the comment: &lt;code&gt;use_colors&lt;/code&gt; must be set while the MultiMesh has no instances, or the per-instance colours silently do nothing. The pond reflections, which were another copy of every glowing thing, went through the same collector.&lt;/p&gt;

&lt;p&gt;The result on the dig test scene, which I use because it is a fixed camera on the open cave:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;View&lt;/th&gt;
&lt;th&gt;Draw calls before&lt;/th&gt;
&lt;th&gt;After&lt;/th&gt;
&lt;th&gt;Fewer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Overview&lt;/td&gt;
&lt;td&gt;2,093&lt;/td&gt;
&lt;td&gt;1,972&lt;/td&gt;
&lt;td&gt;121 (5.8 %)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Close up&lt;/td&gt;
&lt;td&gt;2,012&lt;/td&gt;
&lt;td&gt;1,914&lt;/td&gt;
&lt;td&gt;98 (4.9 %)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Nodes per mushroom cell fell from 31 to 42 down to 7 to 14, counting the lights, halos, water and posts that stay separate. The picture of the mushrooms and grass is the same.&lt;/p&gt;

&lt;p&gt;The frame time on that scene: 57 to 59 fps and a 17.8 ms median the day before, 54 to 60 fps and 16.7 to 18.0 ms after. That is inside the spread of the runs. Five percent fewer draw calls did not make a frame I could measure.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I take from it, and what I do not
&lt;/h2&gt;

&lt;p&gt;Fewer nodes is still the right direction for me. The scene has less to keep in memory, building a cave cell does less work, and the batching sets up the shadow and colour flags in one place. But I will not pretend it paid back the 2.2 ms. On this scene on this machine the GPU or something else was the limit, and the draw calls were not.&lt;/p&gt;

&lt;p&gt;Three habits helped:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hide the suspect before you fix it. Measurement 2 took ten minutes and told me that my first theory was wrong.&lt;/li&gt;
&lt;li&gt;Keep one fixed test scene for each change. The full level run is too long and ends in a slightly different place every time.&lt;/li&gt;
&lt;li&gt;Write down what a number was measured on. The 390 draw calls and 2 ms were from a different run than the 2,093 and 17.8 ms, and I almost added them up.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The part I still do not know
&lt;/h2&gt;

&lt;p&gt;I did not rerun the full level after batching. So I do not know whether the end-of-demo frame is back at 21.9 ms or still at 24.1. There are two explanations and my runs do not separate them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The cave props cost 2 ms and batching gets some of it back, but my test scene hides it because it is limited by something else.&lt;/li&gt;
&lt;li&gt;The 2.2 ms is the camera facing a denser part of the forest and village, and the caves have nothing to do with it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you have a way to tell "this feature costs frame time" from "this camera sees more" in a run that always ends in the same place, I would like to hear it. Do you move the camera to a neutral spot and compare, or render the same view with the feature removed? I have not decided which of those is the better control.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>performance</category>
      <category>godot</category>
      <category>gdscript</category>
    </item>
    <item>
      <title>My Godot level load fell from 34.5 s to 2.7 s, and the best fix removed work nobody needed</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Wed, 11 Nov 2026 12:31:14 +0000</pubDate>
      <link>https://dev.to/nefayran/my-godot-level-load-fell-from-345-s-to-27-s-and-the-best-fix-removed-work-nobody-needed-2e4p</link>
      <guid>https://dev.to/nefayran/my-godot-level-load-fell-from-345-s-to-27-s-and-the-best-fix-removed-work-nobody-needed-2e4p</guid>
      <description>&lt;p&gt;On the morning of 2 November the landing in my Godot 4 game, Planet Wanderer, took 34.5 seconds to load. A week later it takes 2.7. The biggest single step was not threads or caching. A footprint calculation went from 8.3 s to 0.3 s because it was walking models with 50,000 to 400,000 triangles when a copy with a few hundred would do. Below are the steps in the order I took them, with the log line that justified each, and one fix that measured as nothing.&lt;/p&gt;

&lt;p&gt;All times are from one Windows PC with 8 worker threads, read from a timing line the game prints for each part of the load. Each number comes from a separate run, so treat anything under about half a second as noise.&lt;/p&gt;

&lt;h2&gt;
  
  
  What "landing" loads
&lt;/h2&gt;

&lt;p&gt;When the player picks a landing spot and presses "Sit here", the game builds a camp around the rover. It lays out two small camps and a town, places a hundred or so props, places the people who live there, plants grass and flowers, and works out where each thing stands so the grass bends away from it. Props and people are 3D models made from images, so some of them carry 50,000 to 400,000 triangles.&lt;/p&gt;

&lt;p&gt;I had been measuring the load as one number. That number only told me it was bad. Splitting it into named parts, each printed with its time, is what made everything below possible. If you do one thing from this post, do that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: a frame that holds for 36 seconds
&lt;/h2&gt;

&lt;p&gt;After "Sit here", one function placed the camps in a single frame: 9.3 s. Then one function planted the ground around them in a single frame: 36.7 s. The loading ring on screen stood still for most of that, because nothing could draw while the frame was busy.&lt;/p&gt;

&lt;p&gt;The fix was the boring one: make both steps advance a little each frame and let the ring move. Same total work, the screen alive. This did not make the load shorter, but it made it measurable, because the next steps could now be timed one at a time while the game kept rendering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: plants as one buffer (36.7 s in the part, 92 ms for the plants)
&lt;/h2&gt;

&lt;p&gt;Most of that 36.7 s was the ground plants. I moved them into a single &lt;code&gt;MultiMesh&lt;/code&gt; buffer and wrote the transforms into it directly. On the Windows PC the plants alone then measured 92 ms. After this and the next step, the whole landing load went from 34.5 s to 21.6 s.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: the footprint walk, moved to workers (13.1 s + 4.0 s to 8.3 s)
&lt;/h2&gt;

&lt;p&gt;To make the grass lie flat around a tent, the game needs the tent's footprint: which ground cells its triangles cover. The code walked every triangle in GDScript, twice, once for the footprint and once for the feet of the people. The cost was not reading the mesh surfaces (that took 0.3 s in total). It was the walking: 13.1 s and 4.0 s.&lt;/p&gt;

&lt;p&gt;I changed it to one walk that fills both masks, and ran it on &lt;code&gt;WorkerThreadPool&lt;/code&gt;, one task per ground cell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;gid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;WorkerThreadPool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_group_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;func&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="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;jb&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Dictionary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;jobs&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="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;wk&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Dictionary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;_walk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jb&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"surfs"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jb&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pm"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;jb&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"mask"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wk&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"mask"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;jb&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"feet"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wk&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"feet"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&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;-&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;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"camp footprints"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nc"&gt;WorkerThreadPool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_group_task_completed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gid&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="n"&gt;planet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_tree&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;process_frame&lt;/span&gt;
&lt;span class="nc"&gt;WorkerThreadPool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;wait_for_group_task_completion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading scene nodes and meshes must stay on the main thread, so a first pass on the main thread collects each model's vertices and indices into plain arrays, and the workers only do arithmetic on those. The &lt;code&gt;await&lt;/code&gt; on the frame loop keeps the ring moving while they run. Result: 8.3 s on 8 threads, and the frames kept coming.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: the fix that measured as nothing
&lt;/h2&gt;

&lt;p&gt;The camp build was almost entirely props: the "heart" of the camp took 4.2 s of 4.4. A hundred things were each being repainted (materials adjusted, one by one). My idea: paint the first thing of each model path, and let the rest be copies of it.&lt;/p&gt;

&lt;p&gt;I added &lt;code&gt;first_of(path)&lt;/code&gt;, kept the first painted node, and duplicated it for the rest. The heart went from 4.2 s to 4.6 s. Slower, within noise.&lt;/p&gt;

&lt;p&gt;The reason was in the data, not the code. At the first camp every prop is the first of its path, so there were no copies to share. I only saw that because I added a per-model timing line next time instead of re-running the stopwatch around the whole function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: it was the disk read, 180 to 300 ms per model
&lt;/h2&gt;

&lt;p&gt;The per-model line said the time was almost all the first read of each model from disk: 180 to 300 ms for each of about 30 models. Painting was 0 ms. Copies and far copies cost 2 to 35 ms.&lt;/p&gt;

&lt;p&gt;So the fix was to start reading them earlier. The screen where you choose a landing spot comes before the build, and &lt;code&gt;ResourceLoader&lt;/code&gt; can load in the background while it is open:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="n"&gt;static&lt;/span&gt; &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;warm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;void&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;p&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;paths&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;_warm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nc"&gt;ResourceLoader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="n"&gt;_warm&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;true&lt;/span&gt;
        &lt;span class="nc"&gt;ResourceLoader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load_threaded_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The place-selection screen requests all 59 files (the models and their far copies, and the people). When the camps are built the requests are already finished and the "read" is a lookup. Measured: camp near the landing 6,957 ms to 479, town 3,378 to 617, heart props 4,924 to 29. Whole landing load 22.8 s to 13.6 s.&lt;/p&gt;

&lt;p&gt;One trap here: &lt;code&gt;warm()&lt;/code&gt; keeps the requests, and something has to collect them afterwards or they pile up in memory. A &lt;code&gt;forget_firsts()&lt;/code&gt; call frees them once the camps are up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: stop walking the big model (8.3 s to 0.3 s)
&lt;/h2&gt;

&lt;p&gt;The footprint walk was still the largest part, 8.3 s on 8 workers. I looked at which triangles it walked and found it went through every mesh under every prop, including the full 50,000 to 400,000 triangle model, and also the model's far copy: the low-triangle stand-in the game shows at a distance.&lt;/p&gt;

&lt;p&gt;For a footprint on the ground, the far copy is enough. Now when a thing has a node called &lt;code&gt;far&lt;/code&gt;, the walk takes that and stops:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;fc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_node_or_null&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"far"&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;fc&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The footprint walk went from 8.3 s to 0.3 s. I checked that the result stayed the same: plants removed 6,026 against 6,041 before, plants trampled 850 against 836. The footprints are nearly the same, because a few hundred triangles at the right silhouette give the same ground cells as 300,000 at the same silhouette. Whole load: 13.6 s to 5.7 s.&lt;/p&gt;

&lt;p&gt;This is the step I would have missed if I had stopped at "use more threads". Eight threads took 17 s of work down to 8.3 s. Doing less work took it to 0.3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: a release that came too early (1.7 s to 0.3 s)
&lt;/h2&gt;

&lt;p&gt;The locals' camps took 1.7 s in one frame, and the per-model line showed they were reading their people's models from disk again. The cause: &lt;code&gt;forget_firsts()&lt;/code&gt; freed the pre-read models right after the camps were built, before the locals, which use the same files. I moved the call to after both locals' camps. Locals' camps 1,762 ms to 321. Whole load 6.3 s to 4.7 s (a different run from the 5.7 above, so the baselines differ).&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: the town's free-ground calculation, and the last models
&lt;/h2&gt;

&lt;p&gt;Two smaller things took the load from 4.7 s to 2.7 s:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The town's locals spent 816 ms in a free-ground calculation per cell, almost all of it on the main thread. I collected the data on the main thread and ran the triangle walk on workers, one cell per worker. 816 to 329 ms, camps 321 to 209. I compared the logged places of the locals before and after: identical to the hundredth of a metre.&lt;/li&gt;
&lt;li&gt;The camp and town cell models and the wounded person with the blanket were still read at the moment of use. Reading them early too: camp 617 to 244 ms, town 736 to 97, the wounded figure 348 to 28. Whole load 4.2 s to 2.7 s.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;What changed&lt;/th&gt;
&lt;th&gt;Whole landing load&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;start (2 Nov)&lt;/td&gt;
&lt;td&gt;one 36.7 s frame&lt;/td&gt;
&lt;td&gt;34.5 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1 to 3&lt;/td&gt;
&lt;td&gt;frames split, plants in one buffer, footprint walk on workers&lt;/td&gt;
&lt;td&gt;21.6 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;models read ahead during place selection&lt;/td&gt;
&lt;td&gt;13.6 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;walk only the far copy&lt;/td&gt;
&lt;td&gt;5.7 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;locals' models kept until used&lt;/td&gt;
&lt;td&gt;4.7 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;town on workers, last models read ahead&lt;/td&gt;
&lt;td&gt;2.7 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What I would do again, and the part I still do not understand
&lt;/h2&gt;

&lt;p&gt;Three habits made this go quickly. Print a named time for every part and keep the line in the log permanently. When a fix does not help (step 4), go to a finer-grained measurement before inventing the next fix. And check that a speed-up did not change the result: I compared plants removed and the locals' positions each time.&lt;/p&gt;

&lt;p&gt;What I cannot explain yet is the other machine. In the game's log from my Linux PC, slicing the ground after the load costs 39 s of CPU, against 5.8 s on the Windows PC. The numbers above are all from the Windows PC. Is that gap fewer fast cores free at that moment, a different Godot build, or something in how the workers are scheduled there? I have not measured it, and I would like to know where else a seven-fold difference like that could come from.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>performance</category>
      <category>godot</category>
      <category>gdscript</category>
    </item>
    <item>
      <title>Godot 4 animation retargeting with free mocap: five traps that look like bad animation</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Mon, 09 Nov 2026 12:31:06 +0000</pubDate>
      <link>https://dev.to/nefayran/godot-4-animation-retargeting-with-free-mocap-five-traps-that-look-like-bad-animation-5bob</link>
      <guid>https://dev.to/nefayran/godot-4-animation-retargeting-with-free-mocap-five-traps-that-look-like-bad-animation-5bob</guid>
      <description>&lt;p&gt;I retargeted free CMU motion capture onto a humanoid character in Godot 4 with &lt;code&gt;SkeletonProfileHumanoid&lt;/code&gt;. Most of the time I lost was not on the animation itself. It went on results that looked like a bad clip or a bad rig and turned out to be a setting, a facing, or a measurement that read the wrong pose. These are the five that cost the most, each with what I saw, what caused it and what fixed it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Wide legs: the source's rest pose is not its stance
&lt;/h2&gt;

&lt;p&gt;The CMU skeleton rests in a wide straddle, with its ankles 0.818 m apart. In the clip itself the actor stands with the ankles 0.268 m apart. I first read the rest and called it "the source's stance", which made a correct transfer look broken.&lt;/p&gt;

&lt;p&gt;The rest also poisons the transfer. &lt;code&gt;SkeletonProfileHumanoid&lt;/code&gt; measures every motion against the rest pose. The source's legs moved inward relative to their straddled rest, so the target's legs moved by the same amount the other way and came out wide.&lt;/p&gt;

&lt;p&gt;The fix belongs on the source import, not the target: &lt;code&gt;retarget/rest_fixer/fix_silhouette/enable = true&lt;/code&gt; on the mocap file. It straightened the source rest while leaving the clip's world pose alone (the ankle gap in the take stayed 0.268 m). On the target the same option did harm: it moved the target's rest 32 cm away from its bind pose.&lt;/p&gt;

&lt;p&gt;If you also straighten the legs in your own export script, turn that off. With both on, the stance came out wrong again.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Inverted arms: &lt;code&gt;overwrite_axis&lt;/code&gt; and a rig that faces −Z
&lt;/h2&gt;

&lt;p&gt;My rig was built facing −Z, so its left side is on −X. The humanoid profile and the mocap face +Z with the left on +X. Both rigs were named correctly; the problem is that &lt;code&gt;overwrite_axis&lt;/code&gt; forces the profile's bone axes onto the target. On the legs and spine that is harmless, because those bones point along Y. On the arms, the only bones that point along X, the forced axis ran against the geometry, and every arm rotation came out inverted: the hands ended far above the hips in poses where the source has them below.&lt;/p&gt;

&lt;p&gt;Turning the character to face +Z removed the conflict. To check facing and side, I put markers in the frame (a sphere at +X, one at +Z and a box on the bone named LeftHand) instead of deducing the side from a render. Two of my three guesses from renders alone were wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Measurements that read the rest pose in a headless run
&lt;/h2&gt;

&lt;p&gt;I measured legs and angles from a script run with &lt;code&gt;godot --headless -s script.gd&lt;/code&gt;. &lt;code&gt;Skeleton3D.get_bone_global_pose()&lt;/code&gt; returned the rest pose on every frame, even after &lt;code&gt;force_update_all_bone_transforms()&lt;/code&gt; and with the AnimationPlayer playing. The animation was applied: &lt;code&gt;get_bone_pose_rotation()&lt;/code&gt; on the same bone changed frame to frame. Only the global composition was stale. The numbers looked plausible, so I drew several wrong conclusions from them.&lt;/p&gt;

&lt;p&gt;Composing the chain by hand gives the right answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;chain&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="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Transform3D&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Transform3D&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IDENTITY&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find_bone&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="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;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;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_bone_pose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;
        &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_bone_parent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&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;t&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a run that renders, the API and this function agree to three decimals.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. 170 degrees of twist on a clip that looks fine
&lt;/h2&gt;

&lt;p&gt;A twist audit built on &lt;code&gt;get_bone_pose_rotation()&lt;/code&gt; reported 160 to 180 degrees of twist on almost every bone of clips that looked perfectly normal. That call returns the pose including the bone's rest orientation. Take the delta from the rest instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gdscript"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;rest_q&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_bone_rest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;basis&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_rotation_quaternion&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;normalized&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;delta&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;rest_q&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inverse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;sk&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_bone_pose_rotation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;normalized&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;normalized&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that change the same audit read about 55 degrees on the upper arms of a lively take and 8 to 14 in a calm one, which is what the eye sees.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. A perfect T-pose at rest and one arm straight up in every pose
&lt;/h2&gt;

&lt;p&gt;This one starts in Blender, before the GLB reaches Godot. I rotated the mesh and the armature with &lt;code&gt;bpy.ops.object.transform_apply(rotation=True)&lt;/code&gt;, one after the other. Only the armature rotated. The skin's bind matrices absorbed the difference, so the exported GLB looked perfect at rest and threw one arm straight up in every animated pose.&lt;/p&gt;

&lt;p&gt;Rotating the data instead keeps the two bound together:&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;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;rig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rest renders cannot show this, so check it with the same markers as in trap 2, in an animated pose.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checks that would have saved me the time
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fix Silhouette on the mocap source only, and the source's stance measured inside the take, never from its rest.&lt;/li&gt;
&lt;li&gt;Facing and left/right verified with markers in Godot before any retarget setting is tuned.&lt;/li&gt;
&lt;li&gt;Bone measurements in headless scripts composed by hand from &lt;code&gt;get_bone_pose()&lt;/code&gt;, and rotations compared against the rest.&lt;/li&gt;
&lt;li&gt;A measurement that stays exactly the same across a parameter change means the change never reached the export. In my case a flag had switched the bones to quaternion rotation, and a later smoothing step kept editing the now inert euler channels.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Judge clips in the engine, from frames captured in Godot, rather than from Blender's clay renders. Six hand-authored versions were rejected in a row while Blender's workbench renders of them looked passable; the first honest look came from frames captured in Godot. Bone world positions in the two agreed to the millimetre when I checked, so a disagreement between the two views is a misreading, not an import bug.&lt;/p&gt;

</description>
      <category>godot</category>
      <category>gamedev</category>
      <category>animation</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Get back what the insurer holds back, and keep a record of what you give away</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Sat, 07 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/nefayran/get-back-what-the-insurer-holds-back-and-keep-a-record-of-what-you-give-away-5dlb</link>
      <guid>https://dev.to/nefayran/get-back-what-the-insurer-holds-back-and-keep-a-record-of-what-you-give-away-5dlb</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz9b453apv6wuiuirs4vr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz9b453apv6wuiuirs4vr.png" alt="Get back what the insurer holds back, and keep a record of what you give away" width="671" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After a fire, a flood or a break-in, some home and renters policies, common in the United States, don't pay the full value of your things at once. They pay part now and hold the rest back until you replace each thing and send the receipt, sometimes by a deadline. If you never ask, that money stays with the insurer. I wanted that claim kept next to the inventory it comes from, so the AllKeep web app now does it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A claim, thing by thing
&lt;/h2&gt;

&lt;p&gt;Start a claim from Home. Add the things from your inventory or type them in. When the insurer's letter comes, write what it paid and held back for each. Mark what you replace and attach the receipt. The card shows what is still owed and how many days are left.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz9b453apv6wuiuirs4vr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz9b453apv6wuiuirs4vr.png" alt="A claim: paid so far, held back, paid back, still owed, and the days left to replace things" width="671" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The message to the adjuster
&lt;/h2&gt;

&lt;p&gt;"Ask for the held-back money" writes the request for the things you have replaced and not yet been paid for. Copy it or open it in your e-mail; the app sends nothing itself. You can add the deadline to your calendar, with reminders 30 and 7 days before.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff0lyr8xaaj0difst72be.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff0lyr8xaaj0difst72be.png" alt="On a phone: a thing in the claim with what the insurer paid and held back" width="390" height="700"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Donations, for tax time
&lt;/h2&gt;

&lt;p&gt;The second record is for what you give away. Pick the things from your inventory or type them in, with the charity, the day, the condition and the value. At tax time the year's total and a CSV are ready, with notes from IRS Publication 526 for a US federal return.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frs3fq0ow8jk3m7fd5pvd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frs3fq0ow8jk3m7fd5pvd.png" alt="The year's donations: the total, the CSV and the notes for a US tax return" width="672" height="900"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both are free and use no AI credits. The Android app doesn't have them yet. Open them in the &lt;a href="https://inventory.allkeep.org/en/app" rel="noopener noreferrer"&gt;web app&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://allkeep.org/en/blog/insurance-claim-tracker-and-donation-record" rel="noopener noreferrer"&gt;Read on AllKeep →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>inventory</category>
      <category>releasenotes</category>
    </item>
    <item>
      <title>WebGPU fails silently: buffer limits, a missing COPY_SRC and default requiredLimits</title>
      <dc:creator>Rodion Kazennov</dc:creator>
      <pubDate>Wed, 04 Nov 2026 12:32:59 +0000</pubDate>
      <link>https://dev.to/nefayran/webgpu-fails-silently-buffer-limits-a-missing-copysrc-and-default-requiredlimits-3lmj</link>
      <guid>https://dev.to/nefayran/webgpu-fails-silently-buffer-limits-a-missing-copysrc-and-default-requiredlimits-3lmj</guid>
      <description>&lt;p&gt;The run finished at 0.04 ms per step, roughly 500 times faster than the simulation should have run at that size. The health report was clean: no NaN, no infinity, the largest force was zero, and every particle had zero neighbours. It was clean because nothing had been computed.&lt;/p&gt;

&lt;p&gt;This happened in &lt;a href="https://github.com/nefayran/protocell-genesis" rel="noopener noreferrer"&gt;protocell-genesis&lt;/a&gt;, a WebGPU simulation I built to test whether a coarse-grained "primordial soup" can assemble itself into a closed vesicle, a bilayer membrane with water trapped inside. In this model it can't, and the repository has the measured reasons. The largest run had 483,268 particles. Over the project, six bugs behaved like the one above: no exception, no error on the page, and numbers that looked plausible or even good. Three of them are specific to WebGPU. Here they are, with what each one looked like and what changed.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A buffer larger than the device allows
&lt;/h2&gt;

&lt;p&gt;At a box size of 85 σ the Verlet neighbour list needed 5,484,474,528 bytes. The device's &lt;code&gt;maxStorageBufferBindingSize&lt;/code&gt; was 4,294,967,292.&lt;/p&gt;

&lt;p&gt;WebGPU does not throw when &lt;code&gt;createBuffer&lt;/code&gt; fails validation. It prints a warning to the console and returns an invalid buffer, and every later dispatch on a bind group that uses it is dropped. The simulation loop kept stepping and kept reading back zeros: &lt;code&gt;max|F| = 0&lt;/code&gt;, 0 non-finite values, 0 neighbours, 0.0405 ms per step.&lt;/p&gt;

&lt;p&gt;The fix is a check before allocation. &lt;code&gt;createSoup&lt;/code&gt; computes every buffer whose size scales with the particle count and compares it with the device's own limits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bindingLimit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;device&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;limits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maxStorageBufferBindingSize&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bufferLimit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;device&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;limits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maxBufferSize&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;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;what&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;candidates&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="nx"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;bindingLimit&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;bufferLimit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;`buffer &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;what&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; needs &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; bytes at N=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;capacityN&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;; `&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="s2"&gt;`maxStorageBufferBindingSize=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;bindingLimit&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, `&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="s2"&gt;`maxBufferSize=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;bufferLimit&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Reading back a buffer without COPY_SRC
&lt;/h2&gt;

&lt;p&gt;Reading data off the GPU means copying it into a mappable staging buffer. If the source buffer was created without &lt;code&gt;GPUBufferUsage.COPY_SRC&lt;/code&gt;, the copy is a validation error. That invalidates the command buffer, so the submit does nothing. The staging buffer was just created, WebGPU zero-initialises new buffers, and &lt;code&gt;mapAsync&lt;/code&gt; resolves normally. You get zeros that look like data.&lt;/p&gt;

&lt;p&gt;Two random-number buffers were missing the flag. All 72 checkpoints on disk had saved a random-number state of pure zeros, so every resumed run seeded the thermostat with 0 for every particle. With identical Langevin noise on every particle, the whole system drifts as one body: the mean squared displacement was 62.32 σ² for all seven species alike, and relative diffusion, which is what lets aggregates find each other, was gone. After the fix, the largest aggregate at step 90,000 grew from 268 to 588.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;usage&lt;/code&gt; is a readable property of a &lt;code&gt;GPUBuffer&lt;/code&gt;, so the whole class of bug costs one bitwise test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;usage&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;GPUBufferUsage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;COPY_SRC&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;readBack: the buffer was created without &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
      &lt;span class="s2"&gt;`GPUBufferUsage.COPY_SRC (usage=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. requestDevice() without requiredLimits
&lt;/h2&gt;

&lt;p&gt;A device requested without &lt;code&gt;requiredLimits&lt;/code&gt; gets the default limits, not the ones the adapter supports. The default allows 8 storage buffers per shader stage. The bond kernels grew past that, pipeline creation with an &lt;code&gt;'auto'&lt;/code&gt; layout failed with a console warning, and every affected pass did nothing. No bonds formed at all.&lt;/p&gt;

&lt;p&gt;The size limits fail the same way, at a particle count instead of a code change. The default &lt;code&gt;maxStorageBufferBindingSize&lt;/code&gt; is 128 MiB. With 1,000 neighbour slots per particle, the list fit at 28,400 particles (113.6 MB) and silently did nothing at 36,400 (145.6 MB).&lt;/p&gt;

&lt;p&gt;The device now asks for the adapter's own maxima:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;limits&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;adapter&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;device&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;adapter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;requestDevice&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;requiredLimits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;maxStorageBuffersPerShaderStage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="nx"&gt;limits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maxStorageBuffersPerShaderStage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;maxStorageBufferBindingSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;limits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maxStorageBufferBindingSize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;maxBufferSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;limits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maxBufferSize&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;h2&gt;
  
  
  4. A NaN guard that could never fire
&lt;/h2&gt;

&lt;p&gt;A safety check threw when particles drifted further than half the Verlet skin, using &lt;code&gt;sqrt(maxDriftSq) &amp;gt; skin / 2&lt;/code&gt;. Every comparison with NaN is false. Once positions became NaN, the drift was NaN and the check passed on every tick. The guard ran the whole time and could not see the failure it was written for.&lt;/p&gt;

&lt;p&gt;The fix scans the IEEE-754 exponent bits of every position on the same tick, before the old comparison. It costs 0.212 ms per chunk of 1,000 steps that takes 331.68 ms, which is 0.064%. On the composition that had been diverging silently, the run now throws at step 1,000 and names 6,957 non-finite components out of 60,750.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Forces from before the box changed size
&lt;/h2&gt;

&lt;p&gt;Drying and rehydration change the box size. The code rescaled the coordinates, rebuilt the neighbour grid and the Verlet list, and then took the next step with forces computed before the rescale. The result is a wrong number, which is harder to spot than zeros.&lt;/p&gt;

&lt;p&gt;A test now pins it from both sides. With the fix, the force buffer on the GPU matches a fresh calculation to within 1.5e-4 at a force scale of 513. Without it, the buffer equals the old forces bit for bit and is off by 313.7.&lt;/p&gt;

&lt;p&gt;It had moved a result I had already written up. At box 30 the largest aggregate came out 2.28 times smaller once the forces were right (three runs on each side, ranges not overlapping), and the effect I had reported for drying cycles shrank from 12.5–14.5× to 8.1–8.4×. A guard that had fired 9 times out of 216 fired 0 times out of 36 after the fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Gates that recognised their input by name
&lt;/h2&gt;

&lt;p&gt;This one has nothing to do with the GPU. The percolation gates, which turn measurements into pass or fail verdicts, found their input by the campaign label, &lt;code&gt;zfB54&lt;/code&gt;, written into the code. The first campaign with a different label flipped the gate to "unproven" without an error. Rows now carry a &lt;code&gt;role&lt;/code&gt; field, and the label is only a fallback.&lt;/p&gt;

&lt;p&gt;A pipeline that identifies its inputs by name goes quiet when someone runs a new experiment, which is exactly when its verdict matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  A seventh: the instrument read zeros
&lt;/h2&gt;

&lt;p&gt;The test that checked whether the page was drawing read the WebGPU canvas through &lt;code&gt;drawImage&lt;/code&gt; into a 2D canvas. It reported 0 changed pixels out of 30,000, on a page that had just drawn 119 frames with 661 instances. The test now uses the scene's own instance counters and a real &lt;code&gt;page.screenshot()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I treat as a failure now
&lt;/h2&gt;

&lt;p&gt;Zero forces, zero neighbours and zero bonds are failures until something shows the physics can produce them. So is a speed-up nobody made. The same goes for a guard that has never fired, until I have seen it fire on purpose.&lt;/p&gt;

&lt;p&gt;WebGPU reports validation errors to the console and to the device's &lt;code&gt;uncapturederror&lt;/code&gt; event, and error scopes (&lt;code&gt;device.pushErrorScope('validation')&lt;/code&gt;) let you await them around a block of work. This project uses explicit checks that throw and name the buffer and the byte count. Whichever you pick, the default is a console warning and a result that looks fine.&lt;/p&gt;

&lt;p&gt;The code, the gate report and the full verdict are in &lt;a href="https://github.com/nefayran/protocell-genesis" rel="noopener noreferrer"&gt;the repository&lt;/a&gt;, and the &lt;a href="https://nefayran.github.io/protocell-genesis/viewer/gallery.html" rel="noopener noreferrer"&gt;snapshot gallery&lt;/a&gt; renders the real checkpoints in any current browser.&lt;/p&gt;

</description>
      <category>webgpu</category>
      <category>typescript</category>
      <category>debugging</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
