diff --git a/crates/nu-plugin-core/src/interface/stream/mod.rs b/crates/nu-plugin-core/src/interface/stream/mod.rs index e8f48939dd..541e1176a0 100644 --- a/crates/nu-plugin-core/src/interface/stream/mod.rs +++ b/crates/nu-plugin-core/src/interface/stream/mod.rs @@ -202,10 +202,13 @@ where if !self.ended { self.writer .write_stream_message(StreamMessage::Data(self.id, data.into()))?; + // Flush after each data message to ensure they do predictably appear on the other side + // when they're generated + // + // TODO: make the buffering configurable, as this is a factor for performance + self.writer.flush()?; // This implements flow control, so we don't write too many messages: if !self.signal.notify_sent()? { - // Flush the output, and then wait for acknowledgements - self.writer.flush()?; self.signal.wait_for_drain() } else { Ok(()) diff --git a/crates/nu-plugin-engine/src/init.rs b/crates/nu-plugin-engine/src/init.rs index 2092935fad..0ba70b49c0 100644 --- a/crates/nu-plugin-engine/src/init.rs +++ b/crates/nu-plugin-engine/src/init.rs @@ -24,7 +24,10 @@ use crate::{ PluginSource, }; -pub(crate) const OUTPUT_BUFFER_SIZE: usize = 8192; +/// This should be larger than the largest commonly sent message to avoid excessive fragmentation. +/// +/// The buffers coming from external streams are typically each 8192 bytes, so double that. +pub(crate) const OUTPUT_BUFFER_SIZE: usize = 16384; /// Spawn the command for a plugin, in the given `mode`. After spawning, it can be passed to /// [`make_plugin_interface()`] to get a [`PluginInterface`]. diff --git a/crates/nu-plugin/src/plugin/mod.rs b/crates/nu-plugin/src/plugin/mod.rs index c7283d10f3..0ec170f4cd 100644 --- a/crates/nu-plugin/src/plugin/mod.rs +++ b/crates/nu-plugin/src/plugin/mod.rs @@ -28,8 +28,11 @@ mod interface; pub use command::{create_plugin_signature, PluginCommand, SimplePluginCommand}; pub use interface::{EngineInterface, EngineInterfaceManager}; +/// This should be larger than the largest commonly sent message to avoid excessive fragmentation. +/// +/// The buffers coming from external streams are typically each 8192 bytes, so double that. #[allow(dead_code)] -pub(crate) const OUTPUT_BUFFER_SIZE: usize = 8192; +pub(crate) const OUTPUT_BUFFER_SIZE: usize = 16384; /// The API for a Nushell plugin ///