DEV Community

Discussion on: The costs of Optional Chaining.

Collapse
 
jharrilim profile image
Joe

This is a fair point, however I feel like the title should be "The Cost of Using A Babel's Polyfill for Optional Chaining", as this really isn't about the cost of the concept of optional chaining itself. Using pretty much any polyfill is going to decrease your performance and create a much larger bundle size. I have tested this out with Typescript using async code targetting ES3 to ES6. The ES3 output was way larger and the performance was much slower than the ES6 version.

Collapse
 
smeijer profile image
Stephan Meijer

You're right. It's definitely the polyfill causing this. In the jsperf link I've posted, you can also see that I did compare it with idx. And both have this issue. Idx does keep the transpiled code a bit smaller though.

We could create something very smart by using proxies and getters, but that will have a serious performance impact in return.

Unfortunately, it will take a long time before we don't need the babel transform any more (or any other polyfill). So at least for now, the issue is quite real. Even though the real cause is the transpiler and not the syntax itself.