Justin Thomas<p><a href="https://enigmatick.social/tags/Enigmatick" rel="nofollow noopener noreferrer" target="_blank">#Enigmatick</a>'s timeline retrieval performance was getting a little slow, so I spent some time optimizing my PostgreSQL queries yesterday. I was able to take the <code>EXPLAIN ANALYZE</code> loop from 17 seconds (an exaggeration of the actual experience in production of a delay of about 2 seconds) to 53ms. It was mostly down to a <code>JOIN</code> that employs a <code>JSONB_AGG</code> to pull in <code>Actor</code> records associated with an <code>Activity</code> to avoid having to make additional calls. The way I was matching against the <code>attributed_to</code> JSONB column was apparently slowing things down.</p><p>I also have some <a href="https://enigmatick.social/tags/Wasm" rel="nofollow noopener noreferrer" target="_blank">#Wasm</a> calls that proactively transform <a href="https://enigmatick.social/tags/E2EE" rel="nofollow noopener noreferrer" target="_blank">#E2EE</a> asymmetrically encrypted messages to symmetrically encrypted vault items. Those run on each load of the timeline, but I was able to use <code>spawn_local</code> to move the processing to a background task for timeline views that don't display encrypted content.</p>