3 ms·
> Chrome’s v8 at least bails out its JIT process if a function is either too big, or if it has too many entries in the switch statement. Is this true? Anyone h
by scotth 12y ago
> Chrome’s v8 at least bails out its JIT process if a function is either too big, or if it has too many entries in the switch statement.
Is this true? Anyone have some sense of why?
- unfunco 12y agoI remember seeing in documentation somewhere that switch statements with more than 128 cases are not optimised in V8, that might be what OP is referring to; however, I've never seen a 128-case switch statement in production, nor have I seen a developer use that many cases in development, refactoring tends to happen earlier in my experience.
- mattgodbolt 12y agoThe error came from the profiler in v8: the main function was tagged as "Could not JIT - too many cases in switch statement" (or similar). I think it's a fair limitation; as you say, more than a few dozen is rare in "real" code - although one might argue this is a pretty common idiom for handling emulation of bytecodes.
- XaspR8d 12y ago> switch statements with more than 128 cases are not optimised in V8 I recently saw this in Petka Antonov's "Optimization Killers"[1], though I've definitely seen it somewhere else as well, because I recall hearing that variables mixed with literals in a switch could trip up the optimizer. [1] https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#4-switch-case https://github.com/petkaantonov/bluebird/wiki/Optimization-k...