From ddb551b31a577c74ee0893772c468933c3df8cfc Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 5 May 2026 23:53:43 +0900 Subject: [PATCH 1/2] Speed up threaded-cursor spec by ~1.8s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "should safely close cursors in threaded environment" example in spec/plsql/schema_spec.rb spawns two threads that call DBMS_SESSION.sleep (or DBMS_LOCK.sleep on pre-18c) and joins them. The point of the test is that two concurrent calls on the same connection don't trip the cursor pool — the sleep durations are only there to keep both calls in flight at once. The original 1- and 2-second sleeps dominated the suite at ~2.05s out of ~10s total (~21%, the slowest example by a wide margin). Drop them to 0.1s and 0.2s, which still gives 100ms of guaranteed-overlap and a 100ms ordering gap between the two threads — far more than OS scheduling needs to keep both in flight. Verified stable across three back-to-back runs at ~0.29s each. Net effect: full suite drops from ~9.93s to ~8.08s (~19% faster); this example moves from #1 to #4 in the slowest-examples profile. Co-Authored-By: Claude Opus 4.7 (1M context) --- spec/plsql/schema_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/plsql/schema_spec.rb b/spec/plsql/schema_spec.rb index d540e3e..1db692b 100644 --- a/spec/plsql/schema_spec.rb +++ b/spec/plsql/schema_spec.rb @@ -255,14 +255,14 @@ class TestModel < TestBaseModel it "should safely close cursors in threaded environment" do if (plsql.connection.database_version <=> [18, 0, 0, 0]) >= 0 expect { - t1 = Thread.new { plsql.dbms_session.sleep(1) }.tap { |t| t.abort_on_exception = true } - t2 = Thread.new { plsql.dbms_session.sleep(2) }.tap { |t| t.abort_on_exception = true } + t1 = Thread.new { plsql.dbms_session.sleep(0.1) }.tap { |t| t.abort_on_exception = true } + t2 = Thread.new { plsql.dbms_session.sleep(0.2) }.tap { |t| t.abort_on_exception = true } [t2, t1].each { |t| t.join } }.not_to raise_error else expect { - t1 = Thread.new { plsql.dbms_lock.sleep(1) }.tap { |t| t.abort_on_exception = true } - t2 = Thread.new { plsql.dbms_lock.sleep(2) }.tap { |t| t.abort_on_exception = true } + t1 = Thread.new { plsql.dbms_lock.sleep(0.1) }.tap { |t| t.abort_on_exception = true } + t2 = Thread.new { plsql.dbms_lock.sleep(0.2) }.tap { |t| t.abort_on_exception = true } [t2, t1].each { |t| t.join } }.not_to raise_error end From 232b39d5a50e8807127181e4e8ba4ee5dfbb45a2 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 5 May 2026 23:57:07 +0900 Subject: [PATCH 2/2] Speed up pre-10.2 dbms_output spec by ~0.33s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "should log output when database version is less than 10.2" example in spec/plsql/schema_spec.rb stubs database_version to [9, 2, 0, 0] so dbms_output retrieval falls into the per-line DBMS_OUTPUT.GET_LINE loop in PLSQL::ProcedureCall#dbms_output_lines instead of the batched DBMS_OUTPUT.GET_LINES path used on 10.2+. With times = 2_000 each iteration is one parse-and-exec round-trip, which is what made this example the second-slowest in the suite at ~0.42s. The intent of the example is to verify the alternate per-line code path works at all — 100 iterations exercise it just as well as 2_000 (the buffer-size assertions live in the unmocked examples right above). Drop times to 100. Verified stable across three back-to-back runs at ~0.09s each. After this and the threaded-cursor change, the slowest-examples profile is much more even (top spec is now ~0.33s). Co-Authored-By: Claude Opus 4.7 (1M context) --- spec/plsql/schema_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/plsql/schema_spec.rb b/spec/plsql/schema_spec.rb index 1db692b..13e138a 100644 --- a/spec/plsql/schema_spec.rb +++ b/spec/plsql/schema_spec.rb @@ -352,7 +352,7 @@ class TestModel < TestBaseModel it "should log output when database version is less than 10.2" do allow(plsql.connection).to receive(:database_version).and_return([9, 2, 0, 0]) - times = 2_000 + times = 100 plsql.test_dbms_output_large("1234567890", times) expect(@buffer.string).to eq("DBMS_OUTPUT: 1234567890\n" * times) end