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

Change communication protocol for DDC's dart:developer implementation #36143

Closed
grouma opened this issue Mar 7, 2019 · 12 comments
Closed

Change communication protocol for DDC's dart:developer implementation #36143

grouma opened this issue Mar 7, 2019 · 12 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. customer-flutter dev-compiler-build P2 A bug or feature request we're likely to work on web-dev-compiler
Milestone

Comments

@grouma
Copy link
Member

grouma commented Mar 7, 2019

Currently DDC logs to the JS console whenever it needs to make a message available. This appears to have some performance overhead, especially if the Chrome inspector is open. A potential better alternative is to provide hooks on the page which DDC can detect and call directly.

cc @jakemac53
cc @vsmenon

@vsmenon
Copy link
Member

vsmenon commented Mar 7, 2019

Agreed. Do you have a sense of whether we need to do this now, or whether it can wait till later (post 2.3)?

@grouma
Copy link
Member Author

grouma commented Mar 7, 2019

This likely can wait post 2.3. I only notice performance issues when the Chrome Inspector is open. Surprisingly it is made even worse if you set the logging level to Default (which hides these type of messages). This implies that it is potentially a Chrome Inspector issue. Nonetheless the alternative I outlined is better for a number of reasons.

@vsmenon
Copy link
Member

vsmenon commented Mar 8, 2019

Ok. We may want to add an abstraction layer here:

https://github.com/dart-lang/sdk/blob/master/pkg/dev_compiler/tool/input_sdk/patch/developer_patch.dart#L27

(and the other 4-5 call sites). E.g., a hook that allows webdev bootstrap to override, but otherwise falls back on theconsole.debug("dart.developer...", ...) call.

@grouma
Copy link
Member Author

grouma commented Mar 8, 2019

That makes sense to me. Is this something @nshahan should pick up?

@jmesserly
Copy link

(unassigned because someone else may pick this up)

FWIW, it was @jacob314 who told me to use console logging, I think because it's easy to subscribe to those events from the Chrome debug protocol. But yeah, since a debugger is listening, we could basically do anything.

What sort of thing is easiest for the debug service to subscribe to? Are there other sorts of events besides console logging?

@jakemac53
Copy link
Contributor

I think adding the ability to provide our own function to call instead of console.debug would be the most straightforward and efficient solution, as opposed to firing events through some other mechanism.

This is mostly only an issue because of how many events flutter fires (one for each frame), if you have an app that does constant animations (like the spinning square) it is really noticeable (and ironically during animations is the worst possible time to be causing jank...).

@jmesserly
Copy link

jmesserly commented Mar 13, 2019

SGTM. The way we've handled this with similar things (such as "ignore whitelisted errors", hot restart) is to have a method on dart. that can be called to set things up. So you could pass in the callback for DDC to use.

Personally, I would remove the "console.debug" calls if they're slow. If the debug service callback isn't registered, then we don't need to log to the console, we can simply do nothing.

@jacob314
Copy link
Member

I agree that we should switch off of console.debug for this. The chrome devtools implementation is far slower than I expected. It is strange it hasn't been optimized more.
Sorry for recommending it!

@vsmenon vsmenon added this to the Dart2.3 milestone Mar 13, 2019
@vsmenon vsmenon added the P2 A bug or feature request we're likely to work on label Mar 13, 2019
@vsmenon
Copy link
Member

vsmenon commented Mar 13, 2019

Adding to 2.3 for now as a p2. Depending on perf, we can bump up or out.

@vsmenon vsmenon modified the milestones: Dart2.3, Dart 2.4 Mar 20, 2019
@vsmenon
Copy link
Member

vsmenon commented Mar 20, 2019

Bumping to 2.4 - if we're hitting perf issues, we can pull forward.

@jmesserly
Copy link

Since y'all need to run JS code anyway, feel free to assign functions directly to the developer library object. For example:

let developer = dart_sdk.developer; // note: import Dart's SDK module somehow
// Intercept "dart:developer" inspect...
developer.inspect = function(object) {
  // ... your JS code here ...
  return object;
};

The current definition is simply:

developer.inspect = function(object) {
  console.debug("dart.developer.inspect", object);
  return object;
};

We can provide a cleaner hook for you if needed. Normally I wouldn't advise mucking with SDK internals, but I think the debug service protocol needs to do that anyway, e.g. to find and call extensions.

@vsmenon
Copy link
Member

vsmenon commented May 21, 2019

Per offline conversation with @jakemac53 bumping from this milestone. We can override in webdev today as well.

@vsmenon vsmenon modified the milestones: D24 Release, Future May 21, 2019
@aadilmaan aadilmaan modified the milestones: Future, D25 Release Jun 4, 2019
@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. customer-flutter dev-compiler-build P2 A bug or feature request we're likely to work on web-dev-compiler
Projects
None yet
Development

No branches or pull requests

7 participants