From 4ed1af039cc94329100a34bdef7727dc3376942b Mon Sep 17 00:00:00 2001 From: Alex Rocha Date: Tue, 17 Feb 2026 19:57:36 -0800 Subject: [PATCH] Decouple test reporter IO from test execution To reduce test reporter overhead on large test suites, we can buffer socket writes so the test thread never blocks on IO --- lib/ruby_lsp/test_reporters/lsp_reporter.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/ruby_lsp/test_reporters/lsp_reporter.rb b/lib/ruby_lsp/test_reporters/lsp_reporter.rb index 613ddbd4c..5a64745c7 100644 --- a/lib/ruby_lsp/test_reporters/lsp_reporter.rb +++ b/lib/ruby_lsp/test_reporters/lsp_reporter.rb @@ -77,6 +77,8 @@ def initialize end #: IO | StringIO @invoked_shutdown = false #: bool + @message_queue = Thread::Queue.new #: Thread::Queue + @writer = Thread.new { write_loop } #: Thread end #: -> void @@ -95,6 +97,8 @@ def internal_shutdown @invoked_shutdown = true send_message("finish") + @message_queue.close + @writer.join @io.close end @@ -227,7 +231,14 @@ def socket(port) #: (String?, **untyped) -> void def send_message(method_name, **params) json_message = { method: method_name, params: params }.to_json - @io.write("Content-Length: #{json_message.bytesize}\r\n\r\n#{json_message}") + @message_queue << "Content-Length: #{json_message.bytesize}\r\n\r\n#{json_message}" + end + + #: -> void + def write_loop + while (message = @message_queue.pop) + @io.write(message) + end end end end