4 ms·
Why is a script compiled to another script up to 30% slower than its target?
by slver 5y ago
Why is a script compiled to another script up to 30% slower than its target?
- capableweb 5y agoEverything is something compiled to something else and eventually machine code, but some do run faster/slower than others. Usually it's mostly about that generated code is more bloated to manually crafted code. Compare generated assembly with manually crafted assembly and you'll see what I mean.
- slver 5y agoThe irony is that for modern processors, generated assembly tends to be faster, because the required optimization is so specific, manually crafting it can almost never match an optimizing compiler. But I get the spirit of what you said.
- capableweb 5y ago> The irony is that for modern processors, generated assembly tends to be faster, because the required optimization is so specific, manually crafting it can almost never match an optimizing compiler. That's interesting, haven't heard of that before. You happen to know of any comparisons that show the difference? Or some other resource on the subject. > But I get the spirit of what you said. Thanks for not being overtly anal about it, which tends to be the norm :)
- fulafel 5y agoThe language wasn't mentioned but often the alternative to assembler is C. C compilers beating hand written assembly comes up in pretty much every discussion of the subject. You can still beat the compiler in many cases if you iterate and analyze enough, but that won't be the case in the first-pass code you'd write. There are some exceptions in areas where compilers have weaknesses, like SIMD code. The thread context is ClojureScript and JavaScript, I think people don't compare JSVM JIT code to hand written assembly that often (tip: node --print-opt-code --print-opt-code-filter=myfunction).
- raspasov 5y agoAs with all benchmarks, a lot of caveats apply. ClojureScript gives you a lot of power, and a lot of tools to easily reason about your code in many asynchronous scenarios. I believe that you if you wrote JavaScript that gives you the same amount of power and immutability guarantees that ClojureScript provides, it will also be slower than a simplistic benchmark that mutates everything all over the place.
- dustingetz 5y agoClojure's immutable/lazy sequence abstraction involves some closures, it does not compile directly to e.g. array looping. I believe the JS VM also is tuned for imperative programming. I'm not sure how much it matters given most people are paying for a virtual dom & diffing, over querying, over-rendering, etc.