Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Channel buffers #12167

Merged
merged 47 commits into from
Sep 17, 2019
Merged

Channel buffers #12167

merged 47 commits into from
Sep 17, 2019

Conversation

gaaclarke
Copy link
Member

Started storing messages for channels sent before the engine is properly setup for handling messages. A second part of this work will be draining the channel buffers inside the framework.

Related issue: flutter/flutter#38914
Related Design Doc (internal only, sorry): https://docs.google.com/document/d/10PEzCpY12P0se7cApopg_RCDJXeCqsr9AicNzsxU3Ds/edit#

@dnfield dnfield requested a review from Hixie September 10, 2019 17:36
Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

Let's try to limit the amount of public API we add for this as much as possible. We should also look at the docs that we have that are user facing, as well as any warnings/errors we print.

/cc @Hixie since this is adding public surface API to dart:ui

@gaaclarke gaaclarke mentioned this pull request Sep 10, 2019
5 tasks
@gaaclarke gaaclarke requested a review from yjbanov September 10, 2019 21:34
Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

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

The web parts LGTM

Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

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

Sorry, there's a bunch of comments, but mostly around the rigor needed for public Dart APIs

PlatformMessageResponseCallback get callback => _callback;
}

/// A fixed-size circular queue.
Copy link
Member

Choose a reason for hiding this comment

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

A per channel, fixed-size circular queue.

Copy link
Member Author

Choose a reason for hiding this comment

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

There isn't anything about the implementation that requires this to be used for channels. It's a generic RingBuffer that could be used anywhere.

class _RingBuffer<T> {
final collection.ListQueue<T> _queue;
int _capacity;
Function(T) _dropItemCallback;
Copy link
Member

Choose a reason for hiding this comment

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

Not clear what this should be. Add doc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, missed responding to this last night.

int get capacity => _capacity;

bool get isEmpty => _queue.isEmpty;

Copy link
Member

Choose a reason for hiding this comment

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

doc

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't say anything :) https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#avoid-useless-documentation

Something like Add a callback when previously queued messages are being dropped due to overflow. The message instance is returned in the callback..

Copy link
Member Author

Choose a reason for hiding this comment

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

That seemed redundant since the docstring for _dropItemCallback says all of that. The intent was to point them to that documentation and not repeat it.

I found examples elsewhere and they put the ivar next to the setter and getter and it gets collapsed in the generated documentation so I don't have to repeat it, so done

Copy link
Member

Choose a reason for hiding this comment

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

Yup, this works.

/// Returns true on overflow.
bool push(T val) {
bool overflow = false;
while (_queue.length >= _capacity) {
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't you want to reuse the resize logic here or extract a part of it? There's some repetition here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, it wasn't trivial since the logic was a bit different and didn't buy many lines, but since you asked there you go.

}
}

typedef DrainChannelCallback = Future<void> Function(ByteData, PlatformMessageResponseCallback);
Copy link
Member

Choose a reason for hiding this comment

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

Doc. Who is supposed to use it. Use See also: for references.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

'Messages on this channel are being sent faster '
'than they are being processed which is resulting '
'in the dropping of messages. The engine may not be '
'running or you need to adjust the buffer size.');
Copy link
Member

Choose a reason for hiding this comment

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

I would gate adjusting the buffer size with a lot of care. It's rarely what the user really wants to do. Make sure we thoroughly explain the cause before recommending this.

return result;
}

/// Returns null on underflow.
Copy link
Member

Choose a reason for hiding this comment

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

When would this happen? Wouldn't consumers check isEmpty first?

Copy link
Member Author

Choose a reason for hiding this comment

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

They should be calling isEmpty. You know how it is, troublemakers don't follow the protocol.

Copy link
Member

Choose a reason for hiding this comment

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

dem delinquent kids these days

return (queue == null) ? true : queue.isEmpty;
}

void resize(String channel, int newSize) {
Copy link
Member

Choose a reason for hiding this comment

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

All public Dart classes and fields need dartdocs.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.


part of ui;

typedef DrainChannelCallback = Future<void> Function(ByteData, PlatformMessageResponseCallback);
Copy link
Member

Choose a reason for hiding this comment

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

dartdoc

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what you are referring to. I updated the docstring to match the ones found in lib/ui/window.dart

/// Storage of channel messages until the channels are completely routed,
/// i.e. when a message handler is attached to the channel on the framework side.
///
/// Each channel has a finite buffer capacity and in a FIFO manner messages will
Copy link
Member

Choose a reason for hiding this comment

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

Make this doc correct (i.e. this class doesn't do anything on web)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

queue = _makeRingBuffer(kDefaultBufferSize);
_messages[channel] = queue;
}
final bool result = queue.push(_StoredMessage(data, callback));
Copy link
Member

Choose a reason for hiding this comment

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

just call this overflowed locally if that's what it's supposed to mean

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

// TODO(aaclarke): Update this message to include instructions on how to resize
// the buffer once that is available to users.
_Logger._printString('Overflow on channel: $channel. '
'Messages on this channel are being discarded. '
Copy link
Member

Choose a reason for hiding this comment

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

The temporal reference isn't clear. Make it clear that it's previously cached messages that are being discarded.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added FIFO notice. I don't want to say previous cached methods because if the size is zero, that is misleading.


/// Changes the capacity of the queue associated with the given channel.
///
/// This could result in the dropping of messages if the newSize is less
Copy link
Member

Choose a reason for hiding this comment

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

nit newSize

Copy link
Member Author

Choose a reason for hiding this comment

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

No article? Done.

Copy link
Member

Choose a reason for hiding this comment

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

ha, I'm sure there was a goomics episode about this but I can't find it anymore.

I actually meant use back-ticks ` around method argument references in docs.


/// Changes the capacity of the queue associated with the given channel.
///
/// This could result in the dropping of messages if the newSize is less
Copy link
Member

Choose a reason for hiding this comment

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

dropping of messages from the front of the queue

/// Remove and process all stored messages for a given channel.
///
/// This should be called once a channel is prepared to handle messages
/// (ie when a message handler is setup in the framework).
Copy link
Member

Choose a reason for hiding this comment

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

nit: i.e.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}
}

final ChannelBuffers channelBuffers = ChannelBuffers();
Copy link
Member

Choose a reason for hiding this comment

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

Still needs a doc (for public fields)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

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

LGTM

@gaaclarke gaaclarke merged commit 0a455a8 into flutter:master Sep 17, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 17, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Sep 18, 2019
[email protected]:flutter/engine.git/compare/63873d9f421f...d1692d4

git log 63873d9..d1692d4 --no-merges --oneline
2019-09-17 [email protected] Update canvaskit backend (flutter/engine#12318)
2019-09-17 [email protected] README for the felt tool (flutter/engine#12323)
2019-09-17 [email protected] Fix continuous event polling in the GLFW event loop (flutter/engine#12320)
2019-09-17 [email protected] Tests for #11283 (flutter/engine#12322)
2019-09-17 [email protected] Improve check to render (or not) a DRRect when inner falls outside of outer on RecordingCanvas (flutter/engine#12229)
2019-09-17 [email protected] Roll src/third_party/dart dd1969a43a..7505b3a5f0 (39 commits)
2019-09-17 [email protected] Channel buffers (flutter/engine#12167)
2019-09-17 [email protected] Make iOS FlutterViewController stop sending inactive/pause on app lifecycle events when not visible (flutter/engine#12128)
2019-09-17 [email protected] Adds PluginRegistry to the C++ client wrapper API (flutter/engine#12287)
2019-09-17 [email protected] Add "type" to getDisplayRefreshRate protocol (flutter/engine#12319)
2019-09-17 [email protected] Add a build command to felt (flutter/engine#12303)
2019-09-17 [email protected] Roll src/third_party/skia df432d5efb70..d545bfbb94ca (1 commits) (flutter/engine#12316)
2019-09-17 [email protected] Roll fuchsia/sdk/core/linux-amd64 from rwf0-... to RRgw-... (flutter/engine#12315)
2019-09-17 [email protected] Roll src/third_party/skia f8486f2c5fb6..df432d5efb70 (1 commits) (flutter/engine#12313)
2019-09-17 [email protected] Roll src/third_party/skia b47704b0bd34..f8486f2c5fb6 (2 commits) (flutter/engine#12312)
2019-09-16 [email protected] Fix the declaration of setSystemGestureExclusionRects to match the PlatformMessageHandler interface (flutter/engine#12306)
2019-09-16 [email protected] Manage resource and onscreen contexts using separate IOSGLContext objects (flutter/engine#12277)
2019-09-16 [email protected] Cleanup in web_ui (flutter/engine#12307)
2019-09-16 [email protected] Made flutter startup faster by allowing initialization to be parallelized (flutter/engine#10182)
2019-09-16 [email protected] Roll src/third_party/skia c22498502cda..b47704b0bd34 (16 commits) (flutter/engine#12304)
2019-09-16 [email protected] Include firefox in check to quote font families (flutter/engine#12288)
2019-09-16 [email protected] Roll src/third_party/dart 7799f424f4..dd1969a43a (2 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
[email protected]:flutter/engine.git/compare/63873d9f421f...d1692d4

git log 63873d9..d1692d4 --no-merges --oneline
2019-09-17 [email protected] Update canvaskit backend (flutter/engine#12318)
2019-09-17 [email protected] README for the felt tool (flutter/engine#12323)
2019-09-17 [email protected] Fix continuous event polling in the GLFW event loop (flutter/engine#12320)
2019-09-17 [email protected] Tests for flutter#11283 (flutter/engine#12322)
2019-09-17 [email protected] Improve check to render (or not) a DRRect when inner falls outside of outer on RecordingCanvas (flutter/engine#12229)
2019-09-17 [email protected] Roll src/third_party/dart dd1969a43a..7505b3a5f0 (39 commits)
2019-09-17 [email protected] Channel buffers (flutter/engine#12167)
2019-09-17 [email protected] Make iOS FlutterViewController stop sending inactive/pause on app lifecycle events when not visible (flutter/engine#12128)
2019-09-17 [email protected] Adds PluginRegistry to the C++ client wrapper API (flutter/engine#12287)
2019-09-17 [email protected] Add "type" to getDisplayRefreshRate protocol (flutter/engine#12319)
2019-09-17 [email protected] Add a build command to felt (flutter/engine#12303)
2019-09-17 [email protected] Roll src/third_party/skia df432d5efb70..d545bfbb94ca (1 commits) (flutter/engine#12316)
2019-09-17 [email protected] Roll fuchsia/sdk/core/linux-amd64 from rwf0-... to RRgw-... (flutter/engine#12315)
2019-09-17 [email protected] Roll src/third_party/skia f8486f2c5fb6..df432d5efb70 (1 commits) (flutter/engine#12313)
2019-09-17 [email protected] Roll src/third_party/skia b47704b0bd34..f8486f2c5fb6 (2 commits) (flutter/engine#12312)
2019-09-16 [email protected] Fix the declaration of setSystemGestureExclusionRects to match the PlatformMessageHandler interface (flutter/engine#12306)
2019-09-16 [email protected] Manage resource and onscreen contexts using separate IOSGLContext objects (flutter/engine#12277)
2019-09-16 [email protected] Cleanup in web_ui (flutter/engine#12307)
2019-09-16 [email protected] Made flutter startup faster by allowing initialization to be parallelized (flutter/engine#10182)
2019-09-16 [email protected] Roll src/third_party/skia c22498502cda..b47704b0bd34 (16 commits) (flutter/engine#12304)
2019-09-16 [email protected] Include firefox in check to quote font families (flutter/engine#12288)
2019-09-16 [email protected] Roll src/third_party/dart 7799f424f4..dd1969a43a (2 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants