Skip to content

On Windows a Ruby program and its threads get 8 MB stacks - #154

Merged
Largo merged 1 commit into
masterfrom
claude/windows-stacks
Nov 8, 2026
Merged

Largo merged 1 commit into
masterfrom
claude/windows-stacks

Conversation

@Largo

@Largo Largo commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Fixes #129. On Windows a Ruby recursion went about a seventh as deep as in CRuby: Windows gives a process's main thread 1 MB of stack and other threads 1.5 MB, while Linux and macOS give 8 MB. Since #150 such a recursion raises a rescuable SystemStackError, but it raised it much too early.

  • ir runs the program on a thread with an 8 MB stack on Windows (Program.cs). The thread is a single-threaded apartment, as Main is, for Windows Forms and WPF. It starts on a named method marked [RubyStackTraceHidden], so backtraces do not show it. Ctrl-C reaches the program because CreateConsole takes the thread it runs on.
  • Thread.new threads get 8 MB on every platform (RubyUtils.ThreadStackSize). On Linux that is what they had already. The memory is reserved, not committed.

Maximum recursion depth on Windows (net10.0, Windows 11 VM)

before after CRuby 4.0.5
JIT-compiled method, main thread 1,586 17,247 10,916
JIT-compiled method, Thread.new 3,016 18,796 10,918
interpreted method, main thread 2,636 18,412 10,916
block recursion ([1].each { f }), main thread 614 5,446 1,150

Linux is unchanged: 21,894 levels for a JIT method on the main thread, 25,364 in a thread.

Testing

  • IronRuby.Tests passes: Windows net10.0 and net8.0 (1088/1088), and Linux net10.0.
  • Util/parallel-sweep.sh: same counts as before (core 44, library 0, language 1, command_line 0, security 2).
  • On Windows: exit 3 returns 3 and runs at_exit, Thread.main == Thread.current holds, and a raised error's backtrace has no extra frame.

Not in this PR

  • Process.kill(:INT, Process.pid) raises SignalException in IronRuby, where CRuby raises Interrupt (rescuable as such). This is older than this change.
  • Ractor_DeepGraph1 stays at 1,000 levels: IronRuby.Tests runs on its own threads, not on ir's.

🤖 Generated with Claude Code

Windows gives a process's main thread 1 MB of stack and other threads
1.5 MB; Linux and macOS give 8 MB. A Ruby recursion went a seventh as deep
as in CRuby there: 1,586 levels of a JIT-compiled method against 10,916.
ir runs the program on a thread with 8 MB (single-threaded apartment, as
Main is), and Thread.new threads get 8 MB everywhere. Windows now: 16,541
levels on the main thread, 18,794 in a thread; CRuby 10,916 and 10,918.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 53 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 468c0db and 7dca063.

Files selected for processing: 3

  • Src/Console/Program.cs
  • Src/Libraries/Builtins/ThreadOps.cs
  • Src/Ruby/Runtime/RubyUtils.cs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@Largo
Largo merged commit 20765dd into master Nov 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: 1 MB thread stacks limit recursion depth (Ractor copy, Ruby recursion) well below CRuby's

1 participant