Question out of curiosity. Is there a reason to ha...
# javascript
e
Question out of curiosity. Is there a reason to having the
tmp
variable in the middle?
Copy code
val otherBuffer = if (otherBytes is Buffer) {
  otherBytes
} else {
  Buffer.from(otherBytes)
}
Is translated to
Copy code
var tmp;
if (otherBytes instanceof Buffer) {
  tmp = otherBytes;
} else {
  tmp = Buffer.from(otherBytes);
}
var otherBuffer = tmp;
Why not assign directly to
otherBuffer
?
j
Because generating the expression if and assigning a variable to another are implemented separately in the lowering to JS
The assumption is that you use a post-processor to compact the JS which will eliminate the intermediate variable
e
@jw makes sense, thanks!
a
Is there any existing post processor doing that ?
j
Tons. The JS ecosystem has 10 tools for everything
😂 2
Uglify, minify, terser, scissors, probably more
Run the production bundle and terser should already be running via webpack
e
I think you can customize the WP configuration to run whatever tool you prefer
h
Atwood’s law ftw
a
Also, starting from 1.9.0 we are doing also such kind of "optimizations" of JS and with 1.9.20 there will be more of them.
🔥 1
e
Thanks @Artem Kobzar, looking forward the final release of 1.9.20. As I mentioned in another thread, I've also seen performance improvements between 1.8.22 and 1.9.0. Hopefully more will come.