-
Notifications
You must be signed in to change notification settings - Fork 222
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
perf: reduce amount of stack memory usage #4103
Conversation
Also, we might want to test with |
dfcd6e5
to
cb17ac6
Compare
Very impressive debugging!! FWIW I managed to sample the backtrace with the + let bt = backtrace::Backtrace::capture();
+ let len = bt.frames().len();
+ log::trace!("{}", len);
+ if len >= 120 {
+ log::trace!("{:?}", bt);
+ } This has the advantage of no LLDB etc, but the disadvantage that you only get the backtraces before the stack overflow.
Though this test is only there to test whether huge queries cause a stack overflow. I'm not sure we get much from it if we change the configs for the platform so it passes! |
Windows now passes!! 👏 👏 |
OoI, how did you identify what should be boxed? Did you just have a sense of what the large things on the stack were? |
Re the error, we could possibly set the |
You can look at individual frames on the stack with lldb and find stuff that is large (i.e. |
Yeah, but prqlc is meant to be used in --release mode. That raises size of query that can fit into 1MB stack memory by a lot. Also, 1MB stack memory is not a lot. An alternative would be to use stacker to resize the stack size dynamically. |
Right right, though I'm saying something a bit different:
(not sure if I'm being clear, happy to speak about it on the call) |
Ah interesting, do you think that's better than doing something like a trampoline? (I understand these things conceptually but have never faced this problem technically, so am learning as much as helping...) |
Exactly. The test is basically saying that "under 1MB stack conditions, we support only queries as long as our long_query case". By not using --release mode in tests restricts these conditions much more that the actual "production" conditions. But now that I've improved the resolver, we can leave the test as is and use these "too" restricted conditions as the benchmark for when we increase memory usage by mistake. So I've never dealt with such problem neither, but I think that:
|
OK great on both counts. Thank you! |
Followup for #2857 (comment)
Refactor a few functions to use heap memory instead of stack memory, to reduce stack memory usage in the case where we recurse into function calls (which happens in long pipelines).
Ideally, stack size of the compile would not grow linearly with PRQL source call nesting depth, but that would be much harder to pull-off than just optimizing our code a bit.
For future reference: my debugging process
_a.prql
,thread backtrace
to get the list of all frames, enumerated. The name of the game is to refactor code such that number of frames in memory goes up, which means that the average size of a frame goes down.settings set frame-format '${frame.index} ${frame.sp} ${line.file.basename}\n'
thread backtrace
=HEX2DEC(RIGHT(C12,9))
(RIGHT is needed because hex2dec cannot parse more than 10 digits)=E11-E12
to get the frame size