Skip to content

Comment on JS performance: try / catch versus checking for undefined parent

Comments

One reason try/catch is slow is that it involves unwinding multiple stack frames, cleaning up as you go, until you hit a catch block.

Try/catch is also a very complicated flow control mechanism (think about how try/catch/finally/return all mesh together) such that a lot of VMs simply don't even attempt to apply any of their fancy optimizations to any function that contains a try/catch.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.