Skip to content

Commit 0a8161e

Browse files
WasmParser: Specialize more hot paths (#153)
With this change, we can achieve 17% speedup on stringify macro benchmark. The performance number is same as the case with CMO but with smaller binary size. | | baseline | CMO | this change | |------------|----------|-------|-------------| | speed (ms) | 198.1 | 172.8 | 169.9 | | size (kb) [^1] | 1739 | 1923 | 1797 | [^1]: swift-6.0.1-RELEASE, macOS 14.4.1 arm64
1 parent fb3426d commit 0a8161e

File tree

5 files changed

+101
-25
lines changed

5 files changed

+101
-25
lines changed

Sources/WasmParser/LEB.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
@usableFromInline
12
enum LEBError: Swift.Error, Equatable {
23
case overflow
34
case integerRepresentationTooLong
45
case insufficientBytes
56
}
67

7-
@inline(__always)
8+
@inlinable
89
func decodeLEB128<IntType, Stream>(
910
stream: Stream
1011
) throws -> IntType where IntType: FixedWidthInteger, IntType: UnsignedInteger, Stream: ByteStream {
@@ -32,6 +33,7 @@ func decodeLEB128<IntType, Stream>(
3233
return result
3334
}
3435

36+
@inlinable
3537
func decodeLEB128<IntType, Stream>(
3638
stream: Stream
3739
) throws -> IntType where IntType: FixedWidthInteger, IntType: RawSignedInteger, Stream: ByteStream {

Sources/WasmParser/ParsingLimits.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/// Limits for parsing WebAssembly modules.
2+
@usableFromInline
23
struct ParsingLimits {
34
/// Maximum number of locals in a function.
5+
@usableFromInline
46
var maxFunctionLocals: UInt64
57

68
/// The default limits for parsing.

Sources/WasmParser/Stream/Stream.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@usableFromInline
12
enum StreamError<Element>: Swift.Error, Equatable where Element: Hashable {
23
case unexpectedEnd(expected: Set<Element>?)
34
case unexpected(Element, index: Int, expected: Set<Element>?)

0 commit comments

Comments
 (0)