Rust Is the Future of JavaScript Infrastructure (2021)
Yup, more generally, I&#x27;d say that statically typed languages that compile to native code (Rust, Go, C++, etc.) are necessary to achieve good performance when writing linters &#x2F; formatters, type checkers, compilers, and interpreters (AST- and graph- based workloads).<p>You could frame it as a &quot;failure of JITs in the 2010&#x27;s&quot;.  JavaScript isn&#x27;t a good language to write the TypeScript compiler or a linter, because v8 isn&#x27;t fast enough.<p>The semantics of JavaScript do not allow v8 to be fast enough.<p>IIRC this was precisely why the Dart project was started more than 10 years ago by the original v8 authors.  They were spending a lot of time looking into why real world web page performance was falling off various cliffs in v8.  They realized they needed to change the LANGUAGE in order to be able to write fast programs.  A major use case was developing programs like Google Docs and GMail in the browser, which had to compete with native programs written in C++.<p>JITs are fast in common cases, but they not only have big costs in terms of memory (code storage) and startup time, but they&#x27;re hard to ENGINEER with!<p>Similar story with Python tooling -- the linters, formatters, and type checkers are quite slow due to being written in Python.   mypyc gives a bit of speedup, but it still uses the Python runtime.<p>Related story from yesterday: 
<i>&quot;Even the pylint codebase uses Ruff&quot; (linter in Rust)</i><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=35035618" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=35035618</a><p>---<p>Emery Berger has memorable framing of this -- &quot;Perl, Python, PHP, and JS are the irrational exuberance&quot; languages.<p><a href="https:&#x2F;&#x2F;www.sigarch.org&#x2F;from-heavy-metal-to-irrational-exuberance&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.sigarch.org&#x2F;from-heavy-metal-to-irrational-exube...</a><p>That is, he says that in the 90&#x27;s and 2000&#x27;s, we thought that clock speeds would continually increase, and JITs would get better, and so we could design language semantics without regard to performance -- language that almost REQUIRE slow implementations.<p>(I think his take is about 50% true.  The other 50% is that dynamic languages simply allowed people to produce popular and useful software at a greater rate, especially for the web, so we ended up with a lot of software written in dynamic languages!  Doing web apps in Java vs. Ruby&#x2F;Python&#x2F;JS is a huge difference in productivity, and I&#x27;d say you often end up with a BETTER result, due to increased iteration &#x2F; fast feedback.)<p>---<p>This also tracks with my experience with <a href="https:&#x2F;&#x2F;www.oilshell.org" rel="nofollow">https:&#x2F;&#x2F;www.oilshell.org</a>, where we reverse-engineered the shell in an experimental fashion with Python, and then evolved that implementation into a statically typed language that generates C++ (using MyPy, ASDL, and algebraic data types).<p><i>Oil Is Being Implemented &quot;Middle Out&quot;</i> :<a href="https:&#x2F;&#x2F;www.oilshell.org&#x2F;blog&#x2F;2022&#x2F;03&#x2F;middle-out.html" rel="nofollow">https:&#x2F;&#x2F;www.oilshell.org&#x2F;blog&#x2F;2022&#x2F;03&#x2F;middle-out.html</a> (and many other blog posts)<p>This core of the program is the elaborate and strongly typed &quot;lossless syntax tree&quot;, which is basically what&#x27;s used in linters and formatters.<p>Even though I&#x27;ve been using both C++ and Python for &gt;20 years, I was a little shocked how much worse Python is for AST- and graph-based workloads.<p>I&#x27;m looking for references&#x2F;measurements specifically on these types of workloads.  I think a lot of papers about JITs are misleading with respect to them, or at least you have to read between the lines.<p>I&#x27;d say that Python and JS are 10x as slow as native code for &quot;business&quot; and &quot;web app&quot; workloads, and I&#x27;ve never had a problem with them in those settings.  Quite the contrary, I&#x27;ve actually sped up poorly working code in static languages with Python.  If you&#x27;re within 10x of the hardware&#x27;s performance, you&#x27;re doing VERY WELL compared to &quot;typical software&quot;, which has layers of gunk and can be 100x to 1000x too slow.<p>But bare Python and JS (no libraries) are closer to 100x too slow for ASTs and graphs.  This is because of all the allocation and GC overhead -- in both time and space -- in addition to dynamic dispatch, etc.<p>(The funny thing is that Oil is now the most statically-typed shell implementation, even though it&#x27;s nominally written in  Python :)  It uses fine-grained static types, where as shells written in C use a homogeneous &quot;WORD*&quot; representation in C, and strings with control codes embedded in them for &quot;structure&quot; and &quot;types&quot;.  I should probably write a blog post about that ...)<p>---<p>To shine some light on the other side, I&#x27;m still a bit skeptical of Rust specifically, because:<p>- memory management is littered all over the codebase.<p>- Borrow checking seems to work better for stateless&#x2F;batch programs (it thinks about parameters and return values), but linters and type checkers for language servers are STATEFUL: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=34410187" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=34410187</a><p>- Many ASTs are actually graphs<p>- pattern matching can&#x27;t see through boxing apparently ?<p>Also, the author of esbuild tried BOTH Rust and Go, and ended up with Go.  IIRC it performed better because it didn&#x27;t have deterministic destruction on the stack -- GC was more efficient?<p>It seems like a language with both garbage collection and algebraic data types would be nicer, but neither Go or Rust fit that description!<p>Rust makes a lot of sense for kernels and so forth, but for language processors -- especially stateful ones (which includes the Unix shell!) -- I think GC is still a big help.  And we know already know how to make GC fast for that use case, i.e. you don&#x27;t need a GC that scales to 1 TB of memory on 128 cores.