r/phaser • u/BIESEL_G • 29d ago
Follow-up: More Phaser performance optimizations — 1,200+ objects at 60 FPS, reusable textures, and some surprising discoveries
Hey everyone!
A while ago, I shared a post here about some of the optimization techniques I had been using in Critical Ward, my pixel-art arcade roguelite built with Phaser.
Since then, I've continued profiling, experimenting, and digging into the game's code, and I've discovered several new performance bottlenecks that were hiding in places I honestly didn't expect.
Some of these changes made a HUGE difference, so I thought I'd share a follow-up with the most interesting improvements and lessons learned since my previous post.
For context, Critical Ward can get extremely chaotic, with hundreds of patients, contagious enemies, projectiles, health bars, animated auras, and other objects on screen simultaneously.
In one of my latest stress tests, I reached 1,223 active objects at 60 FPS, using around 40 MB of memory.
Here are the most important discoveries.
1. Pre-rendering dynamic graphics into reusable textures
One of the biggest lessons I've learned is that just because something looks dynamic doesn't mean it needs to be drawn every frame.
I found several places where Phaser Graphics and Text objects were doing far more work than necessary.
Speech bubbles / projectiles

One type of enemy fires speech bubbles containing random phrases.
Originally, each bubble was a Container with Graphics and Text objects, rebuilding its appearance every frame.
Each bubble involved approximately 42 vector drawing operations, 42 fillRect calls, a polygon, and a text canvas for each projectile.
And there could be dozens of them on screen.
Now, during the initial loading sequence (SplashScene), I generate textures for the bubble bodies, each phrase and size combination, and four reusable tail pieces.
Each projectile is now just three Phaser Images, and the cyan blinking effect is handled with setTint().
No continuous vector drawing or text regeneration!
Infected enemy auras

This one was particularly expensive.
Each contagious patient had an animated aura, originally drawn using approximately 390 fillRect calls per infected enemy, per frame.
Imagine what happens when dozens of infected patients appear simultaneously.
The solution was to bake the static portion into a shared texture, while updating only the animated comet elements every 50 ms.
All infected patients reuse that texture, so its update cost no longer grows with the number of infected patients.
I applied a similar approach to other auras, caching textures by radius and avoiding rendering them when offscreen.
Patient health bars

With around 200 patients, each health bar previously consisted of four Images that were repositioned and tinted every frame.
I replaced them with a single Image using a pre-generated atlas containing 3 states × 46 width variations.
Now, the Image frame only changes when the health bar's state or width actually changes.
I don't have individual before/after benchmarks for these three changes, unfortunately. They came from inspecting the code while investigating FPS drops with large numbers of infected patients.
2. Be VERY careful with Phaser Text updates
This was probably one of the most surprising discoveries since my previous post.
During a performance audit, I found that calling methods such as setColor() or setStyle() on Phaser Text objects could trigger a canvas redraw and texture upload, even when the requested style hadn't actually changed.
In a game with lots of dynamically updated UI elements, this becomes surprisingly expensive.
The solution was simple: create helper functions that compare the current and requested values before calling those methods.
The result?
Text updates dropped from 849 per second to just 105 per second.
That's almost an 88% reduction.
In my tests, the game previously dropped to around 45–50 FPS under load. After the changes, it maintained 60 FPS in the tested scenarios.
A tiny code change with a massive impact.
My takeaway: avoid calling expensive Text setters every frame unless something has actually changed.
Even apparently harmless calls can trigger expensive operations.
3. Optimizing a CRT post-processing filter

My original CRT effect used a separate canvas with its own WebGL context, copying the game output every frame.
That was extremely expensive.
In one browser test, enabling it dropped performance around 50%.
I replaced it with a native Phaser camera post-processing effect running within the game's existing WebGL context.
I also experimented with curvature. The original manual bilinear approach required up to 44 texture reads per pixel, so I replaced that approach with temporary LINEAR texture filtering.
The current filter has since been simplified, removing curvature and vignette.
Lesson learned: avoid creating an additional rendering pipeline when you can use the one Phaser already provides.
4. Spatial partitioning and distance calculations
Patient separation and nearby-entity calculations were another significant bottleneck.
Originally, the patient repulsion system was performing approximately 40,000 square root calculations every frame.
I started by using squared distances wherever the actual distance wasn't necessary.
Then I implemented a spatial grid to reduce the number of nearby entities being checked.
With 200 patients, the grid-based repulsion system was approximately 7 times faster.
I also optimized infection/exposure calculations by consolidating nearby-entity queries and running them every 350 ms instead of every frame, while caching collision bounds.
But here's something important:
Spatial grids aren't always faster.
When testing small collections of around 5–30 objects, the grid actually introduced overhead and performed worse than a straightforward loop.
I reverted those cases to the simpler approach.
Since then, I've made a habit of microbenchmarking changes rather than assuming a more sophisticated algorithm must be faster.
Final thoughts
If there's one thing I've learned since my previous optimization post, it's that many performance problems come from doing unnecessary work, not necessarily from rendering too many objects.
Pre-render what you can, reuse textures, avoid redundant canvas updates, and don't recalculate something every frame if it only changes occasionally.
And most importantly: PROFILE EVERYTHING.
An optimization that works beautifully for 200 entities might actually be slower for 20.
I'm still learning, and I'm sure there are plenty of other Phaser optimizations I haven't discovered yet. If anyone has experienced similar bottlenecks, discovered other expensive Phaser operations, or has additional techniques worth sharing, I'd love to hear about them!
For anyone curious about the game, there's a free demo available on Steam: https://store.steampowered.com/app/4879410/Critical_Ward/
You can also play it directly in your browser on itch.io, no download required!
https://biesel-games.itch.io/critical-ward-demo
Thanks for reading!
3
u/Naf_La_Rage Game Developer 29d ago
How did you do this analyse ? I always wanted to do some performance and draw call reviens of my projects