6 points by Farer 1 day ago | 37 comments
I believe I have reached a certain level of success. The canvas seems to have excellent performance. Could you take a look at the ongoing test and provide feedback?
https://alpha.breathingworld.com/
solardev 17 hours ago
Switching zoom levels takes a long time to load the assets. The bunny has some temporary displacement relative to the background. Panning results in visible lag.
I don't think vanilla is a magic performance pill. Everything compiles down to vanilla, after all, and in this case this app's performance seems quite a bit slower to me than Leaflet, OpenLayers, OpenSeadragon, Konva, Pixi.js, etc. I haven't looked at your code, but maybe it could benefit from tile-based rendering and asset virtualization?
I also think if this is the extent of your desired usage (rendering graphics on a zooming panning canvas) you're reinventing a wheel that's already been invented, abandoned, reinvented, improved, forked, improved, rewritten a thousand times. Why do you want to? Just for fun? To make an even better one? To make a custom game or mapping engine? Those are all fine, it's just a lot of work with uncertain payoff vs using a ready made library (not necessarily framework).
Just my opinion. I'm a lazy dev though.
Farer 16 hours ago
I also want to mention that the map size is 245,760 x 138,240, which is exactly 128 times 1920 x 1080. I’ve managed to make that enormous map, along with the data for hundreds of thousands of weeds and countless rabbits, run smoothly without issues. It even works perfectly on mobile phones.
If I get the chance, I'll integrate Kafka and set up servers abroad.
solardev 15 hours ago
I wouldn't really call it smooth compared to an optimized mapping lib like the other ones. Have you done any benchmarking by FPS, or even just noticing what happens visually when you pan (things blink in and out of existence, for example).
Keep in mind that it's already more optimized than any code I could write on my own (kudos!), just not as smooth as the big solutions. If you don't want to use them, more power to ya! Just providing one opinion because you asked for it. Not necessarily trying to convince you to do it differently if you don't want to. Typically people will have made up their minds already anyway, lol.
Farer 14 hours ago
Actually, when zooming in or out quickly, there’s a momentary effect where what was previously rendered lingers for a bit. I don't see this as a major issue, considering it aligns with the concept of eventual consistency.
Also, what exactly is the large-scale solution you mentioned? Regarding the movement of the rabbits’ coordinates, it might not appear smooth when zoomed in significantly. This isn't necessarily a performance issue but rather something related to how the animals' coordinates are processed. I plan to improve that part in the future.
Anyway, thanks for your interest. I'll definitely consider your feedback!
solardev 14 hours ago
When you pan (click and drag, or touch and drag on a phone), all the bushes and the background disappear for what feels like a second or two, even if they're the same bushes as before. No network connections are happening during that pan, it's just a redraw that causes them to blip in and out: https://share.cleanshot.com/KvwXCVl7ZpLYk8KzFBN1
On Firefox the panning (before mouseup) is itself much laggier than Chrome. (Firefox generally has slower graphics, in my experience). It also suffers from the disappearing graphics on mouseup issue.
Same thing happens if I zoom in and out, one mousewheel notch at a time - everything momentarily disappears before rerendering.
> Also, what exactly is the large-scale solution you mentioned?
By "big", I just meant literally the larger libraries I mentioned earlier (Leaflet, OpenLayers, OpenSeadragon, Konva, Pixi.js, etc.). They're bigger in both in popularity/mindshare, but also in filesize and complexity, which is what you're trying to avoid. However, they do have optimizations for the graphics rendering pipeline that maybe you can borrow from, if you look at their source code.
Some examples:
* https://openlayers.org/en/latest/examples/icon-sprite-webgl.... (this one in particular is super smooth for me compared to your app's current version, but it uses WebGL)
* https://openlayers.org/en/latest/examples/synthetic-points.h... (demo without WebGL, much laggier)
* https://konvajs.org/docs/sandbox/20000_Nodes.html
* https://www.goodboydigital.com/pixijs/bunnymark/
* http://fabricjs.com//group-dragging
* Benchmarks: https://github.com/slaylines/canvas-engines-comparison?tab=r... (current build seems broken)
Farer 13 hours ago
I'll definitely need to take a proper look at the solutions you mentioned this time. I also remember Konva being very useful in the past. Thank you for the detailed and kind response.
Farer 13 hours ago
Farer 13 hours ago
Farer 16 hours ago
On the server side, you can compensate with better server specifications and resources, but with web front-end development, it's essential to ensure compatibility across various browsers while using minimal resources. This is how you can provide the best possible experience to the largest number of people.
Of course, if you want to avoid relying on other solutions, it's true that you need to be very familiar and experienced with Vanilla JavaScript.
solardev 14 hours ago
It's more that the big name libs for this use case have a lot of optimizations, both server-side (like raster and vector tiling, CDNs) and client-side (asset and viewport virtualizations, prefetches, offscreen canvas rendering, etc.) learned over decades of doing web mapping & graphics that don't seem to be implemented in your app yet. They're all open source, so you can look at their techniques if you want. Especially their performance stress test examples.
I don't mean to make this a philosophical debate about libs vs writing your own code. You asked for opinions about the performance of your app, and I'm just providing one person's feedback. It's better than anything I could've written on my own, but not as fast as the major libs.
Farer 14 hours ago
I also agree that optimizing the canvas for GPU usage is something that definitely requires more research. Since I plan to add more plants and animals, it will be crucial moving forward.
Thanks again for your valuable input!
solardev 14 hours ago
In particular, if you want to go lower-level (i.e. more control over graphics, rather than something optimized for web mapping in particular), I'd look at Pixi.js
Good luck!
Farer 13 hours ago
Farer 16 hours ago
solardev 15 hours ago
Farer 14 hours ago
But when it comes to web front-end development, I often feel that frameworks and libraries shift too much focus away from actual development, making you worry about things that aren’t really necessary. After all, JavaScript in browsers isn’t compiled like other languages. The main thing that reduces loading times is using cache, right?
solardev 13 hours ago
I think a differentiation between a full framework (like Next.js) and a lib (like a Canvas rendering lib) is helpful here. There's a lot more that goes into modern web graphics rendering than just caching, including optimizations within JS itself, its interactions with Canvas and the DOM, WebGL, WebGPU/WASM for expensive calculations, virtualizations, tiling, transformations/filters, etc.
I'm not a graphics programmer so I can't get into much detail here, but I think of it as the difference between making a game in an existing engine (Godot, Unity, Unreal) vs trying to make your own engine and rendering pipelines. It all compiles down to machine code, but their optimizations can be several orders of magnitude better than what a solo dev can realistically write in their own time.
With Canvas rendering, there's been a lot of techniques that companies have worked on over the years. Take a look at Felt, for example, to see a full web app that makes extensive use of render optimizations. They have a nice writeup about it: https://felt.com/blog/from-svg-to-canvas-part-1-making-felt-.... Figma too, but it's less a direct comparison to your app.
Farer 13 hours ago
P.S. Are you a web front-end specialist?
solardev 13 hours ago
Lol, there's no shortage of that in the web world! Every two years or so, right when I feel like I kinda sorta mastered something, it's obsolete and replaced by the new shiny...
> Are you a web front-end specialist
Yes, sort of? I'm a frontend dev with some past full stack experience, but it's all mostly self-taught and I don't have a real comp sci or math background, which means a real weakness when it comes to data structures and algorithms. Especially for graphics, it's a hindrance.
I just happened to grow up with the Web, having learned HTML before CSS and JS were invented, and kinda sorta kept up with it over the decades. Overall I'm a pretty mediocre dev though, especially when it comes to algorithmic optimizations, so you'll have to find someone else for help with that part :) Maybe reach out to some of the lib authors after reviewing their code?
Farer 4 hours ago
satvikpendem 19 hours ago
Farer 17 hours ago
solardev 17 hours ago
Probably doesn't matter much for performance. It all gets stripped away during build anyway.
Farer 16 hours ago
As a side note, I was never really fond of jQuery, even when it first came out, and it ended up becoming almost obsolete. Lately, I'm also not entirely happy with the direction React and Next.js are heading. It could just be because I've grown so accustomed to Vanilla JavaScript.
solardev 15 hours ago
That's fine, you can still use Typescript with vanilla JS and not use any frameworks. Typescript shouldn't result in unnecessary code in production. It's just developer hinting during dev, but it gets removed during the build.
If you don't want to use a build tool at all, you can also use JSDoc formatting to provide some basic type and parameter information. Your IDE can still use that to provide hints.
It's totally up to you. If it's a solo dev codebase that only you ever see and you don't want to type it, then don't :) If you do end up wanting to share the code though, Typescript makes it a lot easier for other devs to use because they can instantly see when something is wired up wrong during development.
Farer 14 hours ago
I really like TypeScript as well. In fact, the back-end of this project is developed with .NET 8.0, and since TypeScript gives off a similar vibe to C#, I genuinely enjoy using it.
I've already made the web front-end open source: https://github.com/Farer/breathingworld_client_web
Even though I’m using Vanilla JavaScript for personal preference and to minimize performance issues, I’ve also been concerned about potential challenges when collaborating with others in the future. I’m currently looking for collaborators, but it hasn’t been easy. Honestly, I might be going against the trend, but that’s a possibility I’m aware of.
wruza 3 hours ago
Farer 3 hours ago
Is the final HTML and JavaScript code generated clean and without unnecessary bloat? As always, minimizing the resources that a first-time visitor has to download is one of my main goals as well.
wruza 3 hours ago
As of bloat, it depends on your tsconfig (ts part, not vite). If you set ts up to modern standards (es20xx), it emits code basically verbatim. If you’re gonna support ancient browsers, it will have to emit some es-to-es boilerplate. See tsconfig.json reference for details. Everyone - editor/lsp, tsc, vite, eslint - look into this file.
Typescript’s general idea is to just erase types, but they added some es version practicalities cause otherwise that would create a whole “pipeline” yet again for a common use case.
Farer 3 hours ago
wruza 1 hour ago
Vite vs React vs Next is crates vs oranges vs boxed oranges.
I know react but never touch it. React, vue, svelte are “state management”. I’m using mithril.js with POJOs for my frontends.
Vanilla everything gets messy in interactive apps, and I come up with a poor man’s mithril usually, then rewrite for it.
Farer 25 minutes ago
satvikpendem 15 hours ago
Farer 14 hours ago
satvikpendem 9 hours ago
Farer 4 hours ago
Farer 4 hours ago
1 day ago