Skip to content
Community Arts Journal

Creative Technology

Cross-Device Performance and Computational Sustainability in Three.js

Identifying an Unexpected Performance Discrepancy

As the Community Arts installation becomes increasingly developed, performance has become an important consideration.

I recently asked my sister to access the website using her relatively new iPhone. Surprisingly, the installation appeared noticeably sluggish, despite functioning relatively well on my considerably older phone.

This challenged my assumption that newer hardware would necessarily provide a better experience.

The sluggishness was apparent even before she began manipulating the tower, suggesting that the issue may relate to the continuous rendering of the environment rather than exclusively to the interaction system.

This observation is particularly relevant because I am considering introducing additional procedural animals and developing a more sophisticated painterly aesthetic.

Before expanding the installation, I need to establish why the existing environment performs inconsistently across devices.

Investigating Device Pixel Ratio

One potential explanation is the difference in device pixel ratio.

Three.js can render a scene at a resolution corresponding to the physical pixel density of a device. On high-density displays, this may result in substantially more pixels being rendered than are necessary to represent the scene at its apparent on-screen dimensions.

For example, a device pixel ratio of three results in nine times as many rendered pixels as a ratio of one, assuming identical CSS dimensions.

One possible optimisation would be to cap the renderer's pixel ratio:

renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));

On a device that would otherwise render at a pixel ratio of three, reducing the ratio to 1.5 would reduce the number of rendered pixels by approximately 75%.

This could potentially reduce GPU workload without changing the apparent dimensions of the installation.

However, the resulting performance improvement would depend on whether rendering resolution is a significant contributor to the existing bottleneck.

Browser and Hardware Differences

Pixel density is only one possible explanation for the performance discrepancy.

Differences between browser rendering engines, GPU drivers, shader execution, transparency handling, memory allocation and thermal management could also influence the observed behaviour.

The installation contains several elements that may contribute towards GPU workload, including animated vegetation, shadows, environmental textures and transparent materials.

Transparency is particularly relevant because overlapping transparent surfaces can require the GPU to process the same screen regions multiple times.

This may become significant within an environment containing grass, foliage and clouds.

I therefore need to investigate the individual computational costs of these features rather than assuming that a single optimisation will resolve the problem.

Establishing a Performance Baseline

Before introducing procedural animals, I would like to establish a performance baseline for the existing installation.

This could include measurements of frame rate, frame time, loading time, rendering resolution, draw calls, geometry complexity and memory consumption.

These measurements could subsequently be compared against versions containing the procedural magpies and alternative painterly rendering techniques.

Potential optimisation strategies include reducing unnecessary geometry, sharing materials and textures between repeated objects, limiting rendering resolution, reducing overlapping transparent layers and simplifying expensive lighting calculations.

I would also like to investigate suspending unnecessary rendering and animation when the installation is outside the visitor's viewport.

This is particularly important because the tower is intended to be an optional experience. Continuing to render a complex three-dimensional environment while someone is reading information further down the website would consume computational resources without contributing towards their immediate experience.

Distinguishing Animation from Rendering Cost

One consideration that emerged during this investigation was the relationship between an animal's visible behaviour and its computational cost.

Simplifying an animal's behaviour does not necessarily produce a significant performance improvement.

An animal performing a relatively elaborate movement may not be considerably more expensive to render than an animal remaining stationary if both use the same geometry, materials and animation calculations.

The actual computational implications depend on the implementation.

Procedural movement could introduce additional CPU workload if it requires frequent behavioural calculations, while the model's geometry, materials and shadows could contribute towards GPU workload independently of its visible behaviour.

Consequently, optimisation should be informed by profiling rather than exclusively by assumptions about visual complexity.

Computational Sustainability

I want to avoid continuously adding geometry, animations, shaders and environmental effects without assessing their cumulative cost.

A visually impressive installation becomes less effective if visitors cannot interact with it comfortably on their own devices.

This is especially relevant for a community-focused organisation that should remain accessible to individuals using a wide range of hardware.

I would like to establish a performance budget against which future features can be evaluated.

The objective is not necessarily to maximise graphical fidelity or achieve an identical visual experience across every device. Instead, I want to preserve the essential artistic qualities of the installation while maintaining responsive interaction.

The performance discrepancy observed on my sister's iPhone has reinforced the importance of testing these assumptions directly before committing to further development.

References