Skip to content

Streamlined New Data ABI#1706

Open
jmschonfeld wants to merge 1 commit intoswiftlang:mainfrom
jmschonfeld:data-streamlined-abi
Open

Streamlined New Data ABI#1706
jmschonfeld wants to merge 1 commit intoswiftlang:mainfrom
jmschonfeld:data-streamlined-abi

Conversation

@jmschonfeld
Copy link
Contributor

A new ABI representation of Data that is streamlined to reduce client code size and improve average runtime performance.

Motivation:

Data's representation today (a combination of 4 possible representations: empty, inline, small, and large) suffers from significant code size and runtime performance issues due to generic handling of possible representations. A single, streamlined representation reduces the code size and runtime requirements to read/write the bytes.

Modifications:

A new DATA_LEGACY_ABI build flag is added to build the existing ABI representation (required to maintain on ABI stable platforms like macOS). When this flag is not provided, a new representation (not ABI compatible with the existing representation) is built and used instead.

Result:

On non-ABI stable platforms (Linux, Windows, WASM, Android, etc.), benchmarking shows the following throughput performance changes:

Operation Empty Inline Small Large
== (equal inputs) Unchanged Improved (8%) Improved (53%) Improved (72%)
!= (unequal inputs) N/A Regressed (-17%) Unchanged Unchanged
.count Improved (35%) Unchanged Improved (5%) Improved (348%)
.bytes Improved (156%) Improved (90%) Improved (740%) Improved (1362%)
Iteration (via indices) Unchanged Regressed (-42%) Improved (6%) N/A*
Iteration (via iterator) Unchanged Unchanged Improved (14%) N/A*
.append(UInt8) N/A Regressed (-99%) Improved (14%) Improved (31%)
.insert(_:at:) N/A Regressed (-36%) Improved (9%) Unchanged

*Iteration of a large slice took long enough that the benchmarking suite was not able to measure its throughput

Overall, most operations see a significant performance improvement (including .bytes which we expect to be a very common operation sees up to a 1300% performance improvement). There are a few cases which have regressed, mostly in the line data case but given that inline Datas are limited to 14 bytes and many of the inline operations also improved, I expect that these performance regressions are likely worth the tradeoff.

Testing:

Existing unit test coverage applies to the new representation.

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld jmschonfeld marked this pull request as ready for review February 13, 2026 23:50
@jmschonfeld jmschonfeld requested a review from a team as a code owner February 13, 2026 23:50
@jmschonfeld
Copy link
Contributor Author

Full toolchain tests have passed against this change via cross repo testing

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.

1 participant