Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I 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.


> 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-k...


The 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: