为什么 V8 不能优化 try-catch-finally?
Why can't V8 optimize try-catch-finally?
为什么 V8 无法优化 try-catch-finally 块,而其他著名的运行时(SpiderMonkey、Chakra)似乎对此没有问题?
除了问题的优先级相对较低外,没有特别的原因。
这将在某些时候进行优化
如果您以 v8 为目标,您可以将 try-catch 移动到单独的函数,但只有当它是一个真正的性能问题时才应该这样做,否则它只是过早的优化。
"Programmers waste enormous amounts of time thinking about, or
worrying about, the speed of noncritical parts of their programs, and
these attempts at efficiency actually have a strong negative impact
when debugging and maintenance are considered. We should forget about
small efficiencies, say about 97% of the time: premature optimization
is the root of all evil. Yet we should not pass up our opportunities
in that critical 3%" - Donald Knuth
唯一最有可能永远不会优化的函数是
- 带有 "debugger" 语句的函数
- 调用 eval() 的函数
- 包含 "with" 语句的函数
其他优化问题应该会在某个时候得到解决。
为什么 V8 无法优化 try-catch-finally 块,而其他著名的运行时(SpiderMonkey、Chakra)似乎对此没有问题?
除了问题的优先级相对较低外,没有特别的原因。
这将在某些时候进行优化
如果您以 v8 为目标,您可以将 try-catch 移动到单独的函数,但只有当它是一个真正的性能问题时才应该这样做,否则它只是过早的优化。
"Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%" - Donald Knuth
唯一最有可能永远不会优化的函数是
- 带有 "debugger" 语句的函数
- 调用 eval() 的函数
- 包含 "with" 语句的函数
其他优化问题应该会在某个时候得到解决。