←back to thread

7 points Farer | 1 comments | | HN request time: 0s | source

What do you think about developing a web front-end with Vanilla JavaScript to minimize performance issues?

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/

Show context
solardev ◴[] No.41913611[source]
IMO I think this is pretty laggy once you zoom in, at least on my phone (Pixel 7 running Chrome).

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.

replies(3): >>41913830 #>>41913916 #>>41913956 #
Farer ◴[] No.41913830[source]
Ah, the reason you feel it's slow is because the server is located in Seoul, Korea. You're probably not in Korea, which is causing some network latency. If you try adjusting the map to a single spot and wait for a moment without moving it around, you'll notice it runs more smoothly.

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.

replies(1): >>41914898 #
solardev ◴[] No.41914898[source]
Yes, some of it may be network lag (asset prefetching can help) but some of it is also just UI jank that has nothing to do with the network.

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.

replies(1): >>41914999 #
Farer ◴[] No.41914999[source]
Okay, thanks. I have one question. What exactly do you mean by something disappearing and reappearing when panning? Could you explain the phenomenon in a bit more detail?

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!

replies(1): >>41915571 #
solardev ◴[] No.41915571[source]
> What exactly do you mean by something disappearing and reappearing when panning? Could you explain the phenomenon in a bit more detail?

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)

replies(3): >>41915680 #>>41915748 #>>41915859 #
1. Farer ◴[] No.41915859[source]
And the map UX isn’t complete yet. I also plan to finish a smooth map UX like Google Maps or the ones you mentioned. I’d appreciate it if you could keep an eye on it a bit longer.