The huge stack size used in Codeforces judge system

Revision en1, by dzhi, 2023-07-11 01:05:36

It appears that Codeforces' judgement system uses a rather huge stack size (maybe 256 MB or even more). A typical example is a DFS solution on a large tree with 200000 nodes, potentially a stick/chain of 200k nodes so the call stack has 200k frames!

Such a huge stack size, likely was introduced to allow DFS or other recursive solutions, which is considered as a bad practice and usually discouraged in production software system:

  • Software systems are usually multi-threaded (dozens or even hundreds of threads) to leverage all the CPU cores and be flexible to network/disk IO delays. Individual threads can not have a huge stack size due to memory limits.
  • With a huge stack size, most of the memory reserved for the stack is likely wasted most times.
  • More importantly, recursive code has the risk of hitting stack overflow at runtime at unpredictable and inconvenient times (like a mine in the field). It is usually discouraged or even forbidden to implement recursive code with unbounded or huge layers.

I wonder what other people's opinion about this, and/or a good reason Codeforces uses a huge stack size.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English dzhi 2023-07-11 01:05:36 1179 Initial revision (published)