From def1232b10e65fef2ea1b58ea06ef0f922460d18 Mon Sep 17 00:00:00 2001 From: "Peter S. Housel" Date: Thu, 13 Jun 2024 21:41:52 -0700 Subject: [PATCH 1/3] io: Improve wrapper-stream dispatch performance Methods on subclasses of often make heavy use of inner-stream, which is an open generic function. To ensure that calls to inner-stream are dispatched efficiently, this change adds sealing definitions for inner-stream on subclasses. * sources/io/streams/wrapper-stream.dylan (inner-stream on ): Make method inline due to its simplicity and performance benefit. * sources/io/streams/indenting-streams.dylan: Seal inner-stream on . * sources/lib/coloring-stream/coloring-stream.dylan: Seal inner-stream on . * sources/lib/progress-stream/progress-stream.dylan: Seal inner-stream on . * sources/lib/llvm/bitcode.dylan: Seal inner-stream on . --- sources/io/streams/indenting-streams.dylan | 1 + sources/io/streams/wrapper-stream.dylan | 2 +- sources/lib/coloring-stream/coloring-stream.dylan | 1 + sources/lib/llvm/bitcode.dylan | 2 ++ sources/lib/progress-stream/progress-stream.dylan | 2 ++ 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sources/io/streams/indenting-streams.dylan b/sources/io/streams/indenting-streams.dylan index 24a3c12ded..de1ed61f6c 100644 --- a/sources/io/streams/indenting-streams.dylan +++ b/sources/io/streams/indenting-streams.dylan @@ -54,6 +54,7 @@ end; define sealed domain make(singleton()); define sealed domain initialize(); +define sealed domain inner-stream(); define constant $spaces :: = " "; // 64 diff --git a/sources/io/streams/wrapper-stream.dylan b/sources/io/streams/wrapper-stream.dylan index b55766e4b2..bea8f7964e 100644 --- a/sources/io/streams/wrapper-stream.dylan +++ b/sources/io/streams/wrapper-stream.dylan @@ -31,7 +31,7 @@ define sealed domain unlock-stream (); define open generic inner-stream (wrapper-stream :: ) => (stream :: ); -define method inner-stream +define inline method inner-stream (wrapper-stream :: ) => (stream :: ) wrapper-stream.%inner-stream; end method inner-stream; diff --git a/sources/lib/coloring-stream/coloring-stream.dylan b/sources/lib/coloring-stream/coloring-stream.dylan index 513931e2e2..1479598aa0 100644 --- a/sources/lib/coloring-stream/coloring-stream.dylan +++ b/sources/lib/coloring-stream/coloring-stream.dylan @@ -10,6 +10,7 @@ end class ; define sealed domain make(singleton()); define sealed domain initialize(); +define sealed domain inner-stream(); define sealed method make (class == , #rest initargs, diff --git a/sources/lib/llvm/bitcode.dylan b/sources/lib/llvm/bitcode.dylan index 5636b295de..6b4d69cc84 100644 --- a/sources/lib/llvm/bitcode.dylan +++ b/sources/lib/llvm/bitcode.dylan @@ -24,6 +24,8 @@ define class () slot bitcode-records :: = make(); end class; +define sealed domain inner-stream (); + define method bitcode-flush (stream :: ) => (); diff --git a/sources/lib/progress-stream/progress-stream.dylan b/sources/lib/progress-stream/progress-stream.dylan index 9e8faf94ca..a18bc79303 100644 --- a/sources/lib/progress-stream/progress-stream.dylan +++ b/sources/lib/progress-stream/progress-stream.dylan @@ -24,6 +24,8 @@ define sealed method make end if end method; +define sealed domain inner-stream (); + define class () end class; From ed83ddcc36bc2e4d35a14600590e3810d1b3c803 Mon Sep 17 00:00:00 2001 From: "Peter S. Housel" Date: Mon, 17 Jun 2024 21:59:18 -0700 Subject: [PATCH 2/3] llvm: Improve bitcode writer method dispatch * sources/lib/llvm/llvm-bitcode.dylan (write-module): Declare the proper type of llvm-module-functions elements. * sources/lib/llvm/bitcode.dylan (stream-record-id): Add type declarations for bitcode-records elements. (write-abbrev-record): Add type declarations for bitcode-abbrev-definitions entries and abbrev-ops elements. --- sources/lib/llvm/bitcode.dylan | 18 ++++++++++-------- sources/lib/llvm/llvm-bitcode.dylan | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sources/lib/llvm/bitcode.dylan b/sources/lib/llvm/bitcode.dylan index 6b4d69cc84..67b4b28300 100644 --- a/sources/lib/llvm/bitcode.dylan +++ b/sources/lib/llvm/bitcode.dylan @@ -348,14 +348,15 @@ end bitcode-block; define method stream-record-id (stream :: , record :: ) => (id :: ) - let record-definition = element(stream.bitcode-records, record, default: #f); - if (~record-definition) + let record-definition :: false-or() + = element(stream.bitcode-records, record, default: #f); + if (record-definition) + record-definition.record-id + else error("record %= not defined for this block type", record); - end if; - record-definition.record-id + end if end method; - /// Abbreviations define class () @@ -493,7 +494,8 @@ end method; define method write-abbrev-record (stream :: , name :: , #rest operands) => (); - let definition = stream.bitcode-abbrev-definitions[name]; + let definition :: + = stream.bitcode-abbrev-definitions[name]; // Output the abbreviation id write-abbrev-id(stream, definition.abbrev-id); @@ -503,7 +505,7 @@ define method write-abbrev-record for (value in operands, op-index = 0 then begin - let op = ops[op-index]; + let op :: = ops[op-index]; select (op.op-kind) #"fixed" => write-fixed(stream, op.op-data, value); @@ -513,7 +515,7 @@ define method write-abbrev-record op-index + 1; #"array" => write-vbr(stream, 6, value.size); - let aop = ops[op-index + 1]; + let aop :: = ops[op-index + 1]; select (aop.op-kind) #"fixed" => do(curry(write-fixed, stream, aop.op-data), value); diff --git a/sources/lib/llvm/llvm-bitcode.dylan b/sources/lib/llvm/llvm-bitcode.dylan index a9a925fc33..0d7d9e1af2 100644 --- a/sources/lib/llvm/llvm-bitcode.dylan +++ b/sources/lib/llvm/llvm-bitcode.dylan @@ -2823,7 +2823,7 @@ define function write-module write-record(stream, #"GCNAME", gc-name); end if; end method; - for (global :: in m.llvm-module-functions) + for (global :: in m.llvm-module-functions) if (global.llvm-function-garbage-collector) do-gc(global.llvm-function-garbage-collector); end if; From 4e4bc748ae9406e3b58710dc660db76850e4783e Mon Sep 17 00:00:00 2001 From: "Peter S. Housel" Date: Wed, 19 Jun 2024 23:47:03 -0700 Subject: [PATCH 3/3] documentation: Note improvements in release notes --- documentation/source/release-notes/2024.2.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/documentation/source/release-notes/2024.2.rst b/documentation/source/release-notes/2024.2.rst index 2d7715a16d..06ab1a171a 100644 --- a/documentation/source/release-notes/2024.2.rst +++ b/documentation/source/release-notes/2024.2.rst @@ -47,6 +47,13 @@ Tools Library Updates =============== +IO +---- + +* The performance of several subclasses of :class:`` + has been improved by sealing the :func:`inner-stream` method for + each subclass. + System ------