Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge expressions blow the stack during evaluation #124

Open
joshdistler opened this issue Jul 31, 2016 · 3 comments
Open

Huge expressions blow the stack during evaluation #124

joshdistler opened this issue Jul 31, 2016 · 3 comments

Comments

@joshdistler
Copy link

Hi Dave.

During some quick testing on the Swift3 branch noticed that if I do evaluation on an extremely long series of calculations (say simple +-*/ stuff on randomly generated integers where the number of operators might be 1000 or more) I'm seeing crashes in DDMathParser.

The strange thing is that it only appears to happen when running the evaluation on a background thread (either via OperationQueue or DispatchQueue).

Is this expected? Am I using it wrong? Obviously if I break down the long series into an array of short calculations, and handle each item separately, it works fine but seems like I shouldn't need to do this.

@joshdistler joshdistler changed the title Possible issue with large evaluation Possible issue with large evaluation? Jul 31, 2016
@davedelong
Copy link
Owner

I just reproduced this, and my gut feeling is that this is an issue related to blowing out the execution stack. When I saw this, I was nearly 400 frames deep in execution, and I'm wondering if at that point we exceed the amount of space that Swift runtime allocates for the execution stack.

@joshdistler
Copy link
Author

Ah. Interesting. Is this Radar material?

@davedelong davedelong changed the title Possible issue with large evaluation? Huge expressions blow the stack Dec 15, 2017
@davedelong davedelong changed the title Huge expressions blow the stack Huge expressions blow the stack during evaluation Dec 15, 2017
@davedelong
Copy link
Owner

I just had the thought that you could do this by doing a DFS traversal of the expression tree without recursing. The current implementation of evaluation is essentially recursing through the entire tree, and on a huge tree, that blows the stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants