Skip to content

perf(extensions): apply backpressure to JSON-RPC stdio stream to prevent memory bloat #893

Description

@ZhuchkaTriplesix

Summary

In lib/core/extensions/rpc/json_rpc_stdio_client.dart:

_lines = stdout.transform(
  boundedUtf8LineSplitter(maxLineBytes: maxLineBytes),
);
_subscription = _lines.listen(
  _onLine,
  onError: _onError,
  onDone: _onDone,
  cancelOnError: false,
);

While boundedUtf8LineSplitter enforces a 32 MB limit per line, it reads the stdout stream eagerly without flow control / backpressure.

If a driver plugin emits a large analytical result set (e.g. tens of thousands of NDJSON lines) faster than the Flutter event loop can process them, decoded strings accumulate rapidly in the stream queue, causing significant memory spikes and risking out-of-memory errors on client machines.

Scope

• Implement stream pause/resume (_subscription.pause() / resume()) when in-flight queue size exceeds a safety threshold.
• Bound the maximum buffered lines awaiting isolate decoding in JsonRpcStdioClient.
• Benchmark memory consumption under simulated heavy NDJSON streaming.

Out of scope

• Changing the underlying stdio transport to shared memory or sockets.

Activity

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

Metadata

Metadata

Labels

marketplaceExtensions marketplace, ExtensionManifestperformanceTheme parser epic label: performancestabilityTheme parser epic label: stability

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions