This site · performance

Making a 3D glass portfolio fast

Five changes took this portfolio from about 46 fps mid-page to 60 fps in the hero and the mid fifties lower down. It removed backdrop blur over the canvas, dropped blend modes, froze the orbs, gave the WebGL field adaptive quality, and deferred its scripts.

Why was the first version slow?

The site runs five apps as live demos inside phone and laptop frames. Behind them a Three.js field draws 2,600 dust particles, a 150-node synaptic lattice with travelling pulses, and holographic shards. The canvas changes on every frame.

The first version held up in the hero and then dropped to about 46 fps mid-page on a mid laptop. The WebGL code was not the main cost. The damage came from the CSS layered on top of the canvas.

Profiling put the causes in this order:

What did blur, blend modes and moving orbs cost?

A backdrop-filter reads the pixels behind an element and blurs them. Over a static page the browser can keep that result. Over a canvas that redraws every frame, the blur has to be recomputed every frame, once per panel.

Every exhibit panel sat over the field, so the browser blurred large regions of a moving image several times per frame. The fix was to stop asking for it. Panels became translucent surfaces: the second background colour at 72 to 86 percent opacity, a 1px border and an inset top highlight.

The small fixed dock keeps a real blur. It is one element, it is small, and it is what makes the site read as glass at a glance. Everywhere else, translucency does the job at no per-frame cost.

mix-blend-mode makes the browser composite an element against everything beneath it with a non-default formula. The cursor used it to invert over content, and the grain layer used it to sit over the field. Both were on screen at all times, so both paid that cost on every frame.

Both went. The cursor is now a plain ring with its own colour, and the grain is a plain tiled layer at low opacity. The three orbs, which used to shift a little on every scroll event and force their blur to be redrawn each time, are now static, and the scroll listener that moved them is gone.

How does adaptive quality work?

The field used to run at one fixed quality for every machine. A phone or an older laptop got the same 2,600 particles and the same pixel ratio as a desktop GPU, and dropped frames to cope.

Now the render loop watches its own frame rate. If fps stays under 45 for two seconds, the field steps down: first the pixel ratio, then the particle count through a smaller draw range. A weak machine settles at a quality it can hold instead of stuttering at one it cannot.

The steps only go down. The particle count and the pixel ratio cap never rise above their starting values, so a fast machine never gets a heavier scene than the one that was tested.

What changed about loading?

Three.js is a 600 KB file. The first version loaded it as a normal script in the head, so the browser stopped parsing HTML until the download finished and the file ran. The page stayed blank for that whole time.

Both scripts now carry defer. The HTML parses to the end, the stylesheet applies, and the scripts run in order once the document is ready. The CDN script also carries a subresource integrity hash and crossorigin set to anonymous, so a changed file fails to run instead of running.

The Content Security Policy sits in a meta tag because GitHub Pages cannot set response headers. It allows scripts only from the site itself and the one CDN, and it blocks inline scripts. The JSON-LD block on each page is data, not code, so it is not affected.

Why did the buttons stop taking clicks?

One bug had nothing to do with frame rate. Each glass panel has a decorative ::after pseudo-element that draws the prism edge along its border. It is positioned absolutely and covers the whole panel.

Without pointer-events set to none, that layer sat above the buttons and swallowed every click on them. The demo buttons looked fine and did nothing. One line fixed it.

The rule is now part of the quality floor for this site. No interactive element is ever covered by a pseudo-element or a decorative layer, and every button is checked by clicking it, not by looking at it.

See it running All posts