Skip to content

Conversation

beccadax
Copy link
Contributor

@beccadax beccadax commented Oct 3, 2025

I’ve had trouble running SwiftParser’s tests—particularly the torture tests in the swiftlang/swift repo—locally in debug mode because some common parser functions would use many kilobytes of stack for each call, consuming the stack too quickly for even a low maximumNestingLevel to control. Break up a number of problematic functions to help with this, and also insert a missing stack overflow check in parseClosureExpression().

Each of the functions I've broken up previously used 4-11K of stack and appeared in a backtrace of a test case that crashed because of a stack overflow, either repeatedly or very close to the top of the stack.

I haven't determined if these changes regress release-mode performance; if they do, we probably shouldn't take them.

@bnbarham
Copy link
Contributor

bnbarham commented Oct 3, 2025

Ooo, thanks for looking into this @beccadax!

swift-parser-cli (Sources/swift-parser-cli) has a performance-test (outputs time + instruction count) that you can use to compare before/after your changes. @hamishknight what repo(s) do you use for the weekly performance tests?

I’ve had trouble running SwiftParser’s tests—particularly the torture tests in the swiftlang/swift repo—locally in debug mode because some common parser functions would use many kilobytes of stack for each call, consuming the stack too quickly for the `maximumNestingLevel` to control. Break up a number of problematic functions to help with this, and also insert a missing stack overflow check in `parseClosureExpression()`.
@beccadax
Copy link
Contributor Author

beccadax commented Oct 4, 2025

I'll wait for Hamish's input, but a quick run on the swift-syntax/Sources directory was actually about 1% faster than main, so that's promising.

@beccadax
Copy link
Contributor Author

beccadax commented Oct 4, 2025

@swift-ci please test

@beccadax
Copy link
Contributor Author

beccadax commented Oct 6, 2025

@swift-ci please test Windows platform

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.

2 participants