Workaround for exceeding stack limit on iOS devices #809
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #806
The root cause of the on-device crash is that the stack grows by an absurd amount in the
ViewTreeBuilder.fromNodescall—so much so that we exceed the 1MB stack limit.In
fromNodes, the stack grows by about 10KB per call tofin the function, regardless of whether the call is actually made. And with 55 call sites, that puts us at ~550KB stack growth and over the limit. I'm not entirely certain, but I suspect that's all coming from type metadata for the massive_ConditionalContentthat is the result ofBuiltinRegistry.lookup(commenting out most of the switch cases in that method dramatically reduces the stack size).We can workaround this by moving that giant lookup switch to a separate view type, which effectively splits the stack growth into two separate phases—one for the
fromNodescall (~177KB, which is 3.2KB perfcall site) and one forBuiltinElement.bodywhich contains the switch (~300KB)—so we don't hit the stack limit anymore.This fixes the immediate issue, but this is still a lot more stack space I would like to be using. Unfortunately, I'm not sure there's anything more we can reasonably do, since I suspect the actual code that's using the stack excessively is being generated by the compiler.