Skip to content

[SwiftSyntax] Keep one 32-bit size accessor per raw node - #3462

Merged
rintaro merged 1 commit into
swiftlang:mainfrom
rintaro:perf-parser-45-raw-size-u32
Oct 5, 2026
Merged

rintaro merged 1 commit into
swiftlang:mainfrom
rintaro:perf-parser-45-raw-size-u32

Conversation

@rintaro

@rintaro rintaro commented Oct 5, 2026

Copy link
Copy Markdown
Member

Remove Int version of RawSyntax.byteLength and RawSyntax.totalNodes and keep only UInt32 ones.

Since nothing was using Layout.decendantCount as-is, it now stores its node count with itself included, as nodeCount so walking the tree don't need +1 arthemic anymore.

Perf neutral, within +-0.15% for parsing and reading.

A raw node's byte length and node count had two accessors each: an
`Int` one and a `UInt32` one, each switching over the node's shape on
its own. Keep only the `UInt32` ones, as `byteLength` and `totalNodes`,
which is the width a layout node stores and sums them in, and widen
where an `Int` is wanted: a `SourceLength`, an array's capacity, slab
sizing, `RawTokenSyntax.byteLength` and the syntax classifier. The
public lengths and positions of the `Syntax` layer stay `Int`.

`AbsoluteSyntaxInfo.advancedBySibling`, which runs for every child of
every node a tree walk reaches, adds them as they are rather than
widening each one to `Int` to narrow it again. Its `&+` cannot overflow
because `makeLayout` builds both sums with checked additions in the same
width, so the root's two preconditions, which could no longer fail, are
removed.

A layout node stores its node count with itself included, as
`nodeCount`, rather than its descendant count, so `totalNodes` is a load
rather than an addition on every child of a walk.
@rintaro

rintaro commented Oct 5, 2026

Copy link
Copy Markdown
Member Author

@swift-ci Please test

@rintaro
rintaro enabled auto-merge October 5, 2026 19:28
@rintaro
rintaro merged commit 624d85e into swiftlang:main Oct 5, 2026
42 checks passed
@rintaro
rintaro deleted the perf-parser-45-raw-size-u32 branch October 5, 2026 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants