Skip to content

Serialize expression compilation requests #18618

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

Merged
merged 7 commits into from
Jun 21, 2018

Conversation

aam
Copy link
Member

@aam aam commented Jun 19, 2018

Requests to compile expressions for debugger evaluation can come to flutter while previously submitted requests are still being handled. This PR serializes all compilation requests to the compiler.

This fixes #18595

@aam aam requested a review from a-siva June 19, 2018 22:03
@aam
Copy link
Member Author

aam commented Jun 20, 2018

PTAL, hopefully this will help @DanTup.

@DanTup
Copy link
Contributor

DanTup commented Jun 21, 2018

Fix seems good to me, thanks! :)

Before:

screen shot 2018-06-21 at 8 20 43 am

After:

screen shot 2018-06-21 at 8 19 41 am

@DanTup
Copy link
Contributor

DanTup commented Jun 21, 2018

@aam Btw, I presume this issue was specific to how evaluations are routed back to Flutter and didn't affect non-Flutter apps? I noticed the fix was in flutter_tools; but I can't repro any issues when running directly on the desktop VM.

_CompileExpressionRequest(this.completer, this.expression, this.definitions,
this.typeDefinitions, this.libraryUri, this.klass, this.isStatic);

Completer<CompilerOutput> completer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field can be in the base classs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done. PTAL if you have a chance

@aam
Copy link
Member Author

aam commented Jun 21, 2018

@DanTup wrote

@aam Btw, I presume this issue was specific to how evaluations are routed back to Flutter and didn't affect non-Flutter apps?

That's right. For standalone Dart VM(non-Flutter apps) there is different(conceptually similar) wrapper. We might have to have similar fix applied to that wrapper(kernel service) too.

@aam aam merged commit 2828a45 into flutter:master Jun 21, 2018
@aam aam deleted the serial-compile-requests branch June 21, 2018 18:13
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
@andrewkolos
Copy link
Contributor

Hello, I realize this PR is from quite a while ago, but could someone explain why this was necessary (@DanTup)? This PR introduced a code comment that says that we serialize compilation requests, but it doesn't explain why we need to. Looking at #18595, I'm guessing that we need recompilation requests to be processed in-order because one compilation request can depend on a previous one. Is that a correct reading?

This has come up because of #151255, which is blocking fixing the top crasher of the flutter tool. I'm considering refactoring the tool's ResidentCompiler APIs to return a pair of futures (one for compilation starting and one for the actual result of the compilation). However, before making these APIs more complicated, I want to make sure that sequencing of compilation requests is actually necessary.

@flutter flutter unlocked this conversation Jul 10, 2024
@DanTup
Copy link
Contributor

DanTup commented Jul 10, 2024

Looking at the original issue I'm not certain, but here's a guess (possible @aam can correct me). I think this might be because the way the expression compilation is done is by just sending strings over a stream bare and a response is received:

>>> expression
<<< response
>>> expression
<<< response

Since these aren't wrapped in anything to indicate which request a response relates to, having multiple requests trying to send requests at the same time might mess things up:

>>> expression1
>>> expression2
<<< response // which expression is this the response to?

My guess is that serialising these into a queue like this was an easy way to fix the issue. It would probably be better if these requests were more structured though (I think we have another open issue somewhere that newlines in an expression will break?). We use something like JSON-RPC for many other tools (like the Flutter daemon), maybe something similar would work here?

(I'm not sure how this is causing your issue though, but I'm not all that familiar with either parts of this code)

@andrewkolos
Copy link
Contributor

andrewkolos commented Jul 10, 2024

Thanks for the response!

(I'm not sure how this is causing your issue though, but I'm not all that familiar with either parts of this code)

Sorry for not elaborating here. I think you are already familiar with dart-lang/sdk#54911 (writing to a process risks an uncatchable error that will often have no meaningful stacktrace), which is affecting the flutter tool greatly. In the flutter tool, we've implemented a workaround to this using runZonedGuarded. However, this implementation is based on IOSink::flush, and you can only have one outgoing flush at any given time. Said another way, any call to this workaround should be awaited before making another call so that we don't end up with two concurrent flush calls. ResidentCompiler is one place in the tool where we make several writes to a process. However, adding awaits there results in a performance regression (see aforementioned #151255). Thinking about this again, I don't think this issue blocks the tool making progress here. I could instead only call the workaround for the last write; it would just be a bit confusing to readers. Sorry if this was hard to follow—in summary, I don't think ResidentCompiler being written to process requests sequentially is blocking anything. It's just the reason is not well documented, and I was hoping I could better understand it and possibly document it myself.

@DanTup
Copy link
Contributor

DanTup commented Jul 11, 2024

Ah gotcha, thanks for the explanation! (and I agree it would be good to document the reasons for this if they're not clear in the code - though it's probably worth some confirmation from @aam or @a-siva if my assumption above is correct before documenting it as such 😄)

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.

VM evaluateInFrame does not always provide a response
5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy