4 ms·
> [...] it's rather pointless in practice unless you can do it at runtime without crashing the browser or causing it to become unresponsive. The snippet i post
by epidemian 11y ago
> [...] it's rather pointless in practice unless you can do it at runtime without crashing the browser or causing it to become unresponsive.
The snippet i posted doesn't crash the browser and seems to take around 1 or 2 milliseconds to run. Considering usual page load times, and if detecting whether TCO works is important for an application, it doesn't seem like an unreasonable solution (albeit pretty ugly hehe).
Thanks for the pointers about languages that don't have this limitation. Unfortunately, it doesn't seem to be the case for Java. This simple recursive function throws a StackOverflowError in less than 100,000 iterations: http://ideone.com/Tf4n3I http://ideone.com/Tf4n3I, and it's not because the program is consuming all physical memory:
/usr/bin/time -v java StackOverflowExample
Exception in thread "main" java.lang.StackOverflowError
at StackOverflowExample.rec(StackOverflowExample.java:7)
at StackOverflowExample.rec(StackOverflowExample.java:8)
at StackOverflowExample.rec(StackOverflowExample.java:8)
...
Command exited with non-zero status 1
Command being timed: "java StackOverflowExample"
User time (seconds): 0.13
System time (seconds): 0.01
...
Maximum resident set size (kbytes): 27000
...