Hacker News new | ask | show | jobs
by hiteshk_msft 3581 days ago
Some of these suggestions are good but some caveats: - Lookup tables- while lookup tables are great, engines might sometimes convert switch statements to lookup tables too- Chakra does this when it's advantageous to do so - Try-catch- this seems like v8 specific advice. Chakra definitely does optimize functions with try-catch in it, and I think SpiderMonkey does too - Freeing memory- setting the reference to null does not necessarily free the memory- it just makes it likelier to get collected when the Garbage Collector runs

Disclaimer: MSFT employee, Engineer on Chakra

4 comments

> Try-catch- this seems like v8 specific advice. Chakra definitely does optimize functions with try-catch in it, and I think SpiderMonkey does too

http://gs.statcounter.com/ certainly suggests that specifically optimizing for Chrome/V8 will benefit the majority of users (58% not including mobile, 50% including mobile). As with all statistics, take with a grain of salt.

Also keep in mind that 50% of users as a whole may not equate to 50% of your users.
> Lookup tables

This one also seems a bit iffy to me, depending on the stage of compilation, how often this code runs, how much information the engine is able to collect, and the size of your table. The initial unoptimized property lookups will likely be slower than if/else statements, and the engine may end up optimizing them with inline caches, which are essentially a chain of if/else comparisons and jumps between dynamically generated code stubs.

> Try-catch

Yep, SpiderMonkey does optimize this case.

> Try-catch- this seems like v8 specific advice.

Carakan doesn't either. But given that nowadays affects some old TVs (but still newish, I doubt most people replace TVs that often…) and Opera Mini's limited JS support… Yeah, okay, that doesn't matter. :)

I vaguely remember firefox choking on try/finally but not try/catch, may have been fixed could have been a dream but in generally try can be tricky