126 points · by qu4k · 6y ago · 63 comments
[1] https://github.com/elsaland/elsa/blob/master/COMPARISON.md
Software that achieves my goal in a focused manner is something i typically enjoy. I don't want it to do everything under the sun, i want it to do one or two things well.
These days, to me, a "lightweight" alternative to Dropbox would be one that focuses on filesharing with none of that other junk.
The other quality of flexible composable systems is that they can be extended with something akin to an AoP system. Non-essential qualities can be woven and applied during composition so that each component doesn't have to implement various features.
A counter example is the find command, it has to implement a predicate language into the tool itself. If it omitted typed objects, a filter engine could select the subset. If find implemented polymorphic values, the predicate would dictate what facets were populated in the structures themselves but our shells don't work that way. A metashell that could define its environment and the streams of structures flowing between components could get us closer to a pervasively composable mode of system construction.
Unix pipelines [2] are awesome, but they aren't the pinnacle. I feel like all of us fall short in creating systems that compose. Most (scalable) systems should be fractal, while most composition is limited to a narrow first-order mode of operation.
It would be nice if one of the benchmarks was more reflective of typical use.
I've done a bunch of work with QuickJS. It's awesome and the performance features you get in return for its tiny footprint is amazing. But compared to JIT-enabled V8 it's incredibly slow.
The one area where it shines compared to V8 is startup time, because the engine is so much lighter. So if you're profiling "time taken to start up and execute one operation" then yes, QuickJS might look better. But that isn't how people use Node/Deno, even when you're creating a CLI tool you're loading a lot of JS and performing a lot of operations.
My guess is that these benchmarks were chosen because the startup time for QuickJS is probably less than the startup time for V8, but I struggle to imagine that V8 is slower once the code has warmed up.
Any meaningful benchmark with JIT runtimes should take several seconds, at a minimum, in my opinion. 8 milliseconds is not enough.
From what I can tell, the benchmark is including the startup time, and it isn't keeping the interpreter warm -- it starts a fresh instance for each iteration of the benchmark.
This is one of the benchmarks: https://github.com/elsaland/elsa/blob/master/testing/bench_s...
Literally a single line of JavaScript.
V8, with or without its JIT, wins hands down. QuickJS may be small and fast to start, but fast actual computations seem not to be its strength (or intended target).
Big discussion of QuickJS last year: https://news.ycombinator.com/item?id=20411154
Maybe a benchmark for JIT runtimes, but you should always keep in mind what the expected use case is.
I recently ported a program from lang X to lang Y. It's a command-line program that you're expected to invoke in your terminal, and it processes some input and then spits something out (not unlike, say, a compiler or a static site generator) but it's expected to be used "interactively" i.e. no significant pauses for processing typical workloads, just like you expect from invoking mkdir or ls. Zero percent of the effort during porting was spent on optimization. In fact, the lang X version uses specialized, algorithmically-sophisticated collection classes, and the lang Y version does the dumbest possible thing. Despite this, for typical workloads, the Y version completes sooner than it takes the X version to do the same. No amount of benchmarking in the world is going to change the fact that the dumb Y version is faster than the clever X version.
For our program to have taken "several seconds, at a minimum" to run would have been a failure case, so there would have been no value in benchmarking that, let alone optimizing for it. I expect the use cases are the same for this project, which is supposed to be processing untrusted scriptlets that need to finish in the smallest amount of wall clock time possible.
It seems that the comparative advantage of QuickJS based solutions is short-lived invocations that benefit from fast startup times. CLI apps/tools and Cloud Functions (e.g. AWS Lambda) seem to fit the bill.
Elsa adds Deno-like HTTP imports and TypeScript support which makes it a strong alternative to Deno for CLI apps/tools.
Deno (V8 on Rust) or the rusty_v8 bindings seems like the better choice for long-lived servers where server-side JavaScript performance is important.
(This happens to me Olaf the time)
As for quickJS, I've really enjoyed using it and was surprised how easy it was to get started with a brew install on a Mac.
I was initially excited about the idea of a Go alternative to some existing js runtimes.
Usually people submit then direct friends/contacts/Twitter followers/etc to the "new" page to upvote. "growth hacking"? :)
I had forgotten that Fabrice Bellard also made one of his signature hacks around JavaScript [1]. This thing is amazing and he created a nicely written and formatted pdf, absolutely lovely.
Then I started doing a simple comparison of the two code bases
(py38.env) zc:deno seanj$ tokei
-------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
-------------------------------------------------------------------------------
JavaScript 169 168797 146555 19948 2294
Markdown 89 10716 10716 0 0
Rust 101 42996 36525 2272 4199
TypeScript 668 117796 85786 20609 11401
-------------------------------------------------------------------------------
Total 1119 342851 281567 43027 18257
-------------------------------------------------------------------------------
(py38.env) zc:elsa seanj$ tokei
-------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
-------------------------------------------------------------------------------
Go 26 1143 949 21 173
JavaScript 31 146438 127418 18927 93
TypeScript 6 4450 1080 2823 547
-------------------------------------------------------------------------------
Total 72 153059 130470 21774 815
-------------------------------------------------------------------------------
The JS portions feel similar (spoiler, same TS runtime) and that Deno has documentation and probably a lot more tests.Here is the a breakdown of the test code in each.
# kept top-k entries after $find . -type f -not -ipath "*test*" -exec rm -f {} \;
(py38.env) zircon:deno_t seanj$ tokei
-------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
-------------------------------------------------------------------------------
JavaScript 107 2991 2564 151 276
Rust 6 5166 4476 141 549
TypeScript 420 40449 34436 1872 4141
-------------------------------------------------------------------------------
Total 614 50564 43246 2219 5099
-------------------------------------------------------------------------------
(py38.env) zircon:elsa_t seanj$ tokei
-------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
-------------------------------------------------------------------------------
Go 3 76 64 0 12
JavaScript 23 137 115 2 20
Plain Text 1 1 1 0 0
TypeScript 5 14 11 0 3
-------------------------------------------------------------------------------
Total 32 228 191 2 35
-------------------------------------------------------------------------------
The JavaScript foot print in both codebases is mostly dominated by the TypeScript runtime and library. (py38.env) zc:deno seanj$ find . -name "*typescript*js" -exec tokei {} \;
-------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
-------------------------------------------------------------------------------
JavaScript 1 147419 128513 18894 12
-------------------------------------------------------------------------------
Total 1 147419 128513 18894 12
-------------------------------------------------------------------------------
(py38.env) zc:elsa_js seanj$ find . -name "*typescript*js" -exec tokei {} \;
-------------------------------------------------------------------------------
Language Files Lines Code Comments Blanks
-------------------------------------------------------------------------------
JavaScript 1 145671 126934 18725 12
-------------------------------------------------------------------------------
Total 1 145671 126934 18725 12
-------------------------------------------------------------------------------
Deno only has 18kloc of js.Deno was originally written in Go, until V8's GC was getting in the way of Go's GC, so they could always work on early versions of Deno, if they are willing to accept the problems with V8 that pushed the project to Rust.
Also, why is it secure ? Is there some kind of sandboxing of the runtime that I have missed ?
We plan on taking the deno route and requiring flags when running a js file to allow specific ops to be called. You can see a demo of this in our filesystem ops