Lurker News

Comments (102) 48 threads

Earlier comments
mkchoi2121 reply#
Super cool! It would be great if you could provide some insight into how you built this and the kind of tricks you had to use to make this possible. Looking forward to a blog post in the future :)
leeoniya1 reply#
a few things:

- the data is flat arrays of numbers
- there is no per-datapoint memory allocation beyond whatever is necessary for the browser to construct the canvas Path2D object. this keeps the memory pressure low and the GC nearly silent.
- the amount of draw commands is reduced by accumulating the min/max data values per pixel
- uPlot does not generate axis ticks by walking the data. it only uses min/max of the x and y ranges and finds the divisions from that.
- there is no mass-creation of Date objects, data is kept in timestamp format except when hovered.
- the date/time formatting is done by pre-compiling templates and not re-parsing them all the time.
- the cursor interaction uses a binary search over the x array

leeoniya1 reply#
another one i forgot

- drawing at exact aligned pixel boundaries to avoid or minimize antialiasing
this makes uPlot charts a bit rougher looking, but the perf impact is quite large.

1wheel1 reply#
How much of an impact does this have?

I prefer the look of things snapped to pixels; I didn't realize it also speed things up!

Continue this thread — 1 reply

_bxg12 replies#
Let this be a lesson that JavaScript is not slow. The DOM can be slow, and downloading large bundles can be slow, and any code can be made slow if you try hard enough to write it poorly. But JavaScript the language is not slow in 2020.

When we talk (or rant) about the performance of JS-based apps - running on the web or in Electron or otherwise - it's really important that the conversation focus on the factors that actually matter.

ComputerGuru1 reply#
No, JS is slow(ish). The GC pressure alone will kill you. This is fast despite being in JS by simply doing as little as possible (while still meeting the requirements on the end result, which is where the genius lies).

The fastest code is no code. No code is fast even with pathologically slow languages/runtimes.

_bxg13 replies#
It's no slower than Python. Probably faster unless you're staying within a native library like NumPy.

But that wasn't my main point: my main point is that people love to rant about "JavaScript apps" while maintaining (willful?) ignorance about what the actual factors are that manifest as the slowness they experience. Sometimes it's poor usage of the DOM. Usually it's ads. It's almost never the unavoidable overhead of JS cycles.

cozzyd#
Javascript is probably at least an order of magnitude faster than Python.
eitland3 replies#
> people love to rant about "JavaScript apps" while maintaining (willful?) ignorance about what the actual factors are that manifest as the slowness they experience.

Are you sure you got this right?
Just because JS is fast[0] doesn't mean we cannot complain about Javascript apps that should have been plain web pages?
It is clearly possible to create advanced Javascript apps that are enjoyable even to people like me.
For most pages I use as a consumer I don't see much value add because of frontend code: I see the value of autocomplete, drag-and-drop etc but I would much prefer if my CPU stopped chewing after web pages were loaded and rendered.
[0]: yes, I agree - in most cases the Javascript language or engine is not the cause of the performance problems on the web

Continue this thread — 3 replies

projektfu#
For me as a user it seems to be: loading google analytics, loading fonts that seem to be improperly cached, loading chat windows, assistance widgets and spies, and dynamically adding things after page load that cause reflows.
petre#
It's among the fastest scripting languages. Only LuaJIT turned out to be faster (than Node.js) in my benchmarks. Node is on par with Dart most of the time and the latter is statically typed.
leeoniya#
Bokeh looks cool, too.
ricardobeat1 reply#
This is awesome, thanks for sharing!

Question: in the demo you load papaparse but the data is delivered as JSON?
Would you mind sharing what your backend looks like for the project where you're using this, and how do you extract all of this data at once from storage?

leeoniya#
> Question: in the demo you load papaparse but the data is delivered as JSON?

good catch, leftovers from original PoC i made locally. the exported data was still in CSV back then. i should clean that up!
> Would you mind sharing what your backend looks like for the project where you're using this, and how do you extract all of this data at once from storage?
i just did a manual export from Analytics. how you get the data out is up to you, but a time-series or columnar database would probably be a good start :)

Load more comments