4 ms·
While it felt a bit chaotically written (maybe due to my lack of in-depth JVM knowledge), a very interesting article. Is there a way to detect when these cases
by chton 12y ago
While it felt a bit chaotically written (maybe due to my lack of in-depth JVM knowledge), a very interesting article.
Is there a way to detect when these cases happen? If there was, the compiler could choose to ignore the @tailrec directive if it wouldn't give any meaningful speed increase.
- bad_user 12y agoThe purpose of `@tailrec` is not necessarily for performance, but more for correctness, otherwise you can end up with recursive functions that blow up the stack pretty fast on large enough inputs. Plus this benchmark only does at most 20 iterations per loop - which means nothing if you want to measure the cost of method calls.
- chton 12y agohmm that's a very good point, I didn't consider that. We'd need additional benchmarking to know what the actual impact is and at what point the @tailrec version becomes more desirable.