Skip to content

CharacterSet: Memory-related Enhancements #2027

Merged
chloe-yeo merged 3 commits into
swiftlang:release/6.4.xfrom
chloe-yeo:pr/characterSet-changes
Jun 9, 2026
Merged

CharacterSet: Memory-related Enhancements #2027
chloe-yeo merged 3 commits into
swiftlang:release/6.4.xfrom
chloe-yeo:pr/characterSet-changes

Conversation

@chloe-yeo

Copy link
Copy Markdown
Contributor

This PR introduces a method that fills a buffer for a specified plane of a BuiltInUnicodeScalarSet so that mutating methods in CharacterSet do not instantiate 8KB of Data that are immediately thrown away after that Data has been used for mutating another buffer via mutating methods such as union and intersection. The method is equivalent in functionality to the previous bitmap(forPlane:isInverted:) method.

Motivation:

This is a change that helps to reduce the memory usage of CharacterSet when trying to fill Annex planes of built-in CharacterSets.

Modifications:

Added a method bitmap(forPlane:isInverted:into:apply:) method and refactored bitmap(forPlane:isInverted:) to call into it to avoid duplicate logic.

Result:

There should be no behavioral change.

Testing:

All the existing unit tests should still pass.

chloe-yeo added 3 commits June 9, 2026 12:02
cleanup 2

clean up 3

clean up 3

cleanup 4

cleanup 4

cleanup

add comments + cleanup

cleanup SetAlgebra file

add comment about safety of immortal pointer

refactor to avoid logic duplication

add fatalError

add check for cachedBMP

explicitly copy Data for built-in sets Data that was initialized by bytesNoCopy

streamline bitmapAll & bitmapEmpty cases handling + callsites

cleanup

remove conditional checking

refactor bitmapBacked init

deduplication

address comments

cleanup

add test for copy

add unit test for union and intersection

add tests + address warnings

address comment

fix

cleanup

add comment + test

add release

only call makeBitmap() inside .bitmapFilled cases

avoid busy work + add union test for additional validation

preserve existing behavior

recover previous method
@chloe-yeo chloe-yeo requested a review from a team as a code owner June 9, 2026 19:05
@chloe-yeo chloe-yeo changed the title CharacterSet: Memory-related Enhacements CharacterSet: Memory-related Enhancements Jun 9, 2026
@chloe-yeo

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@chloe-yeo chloe-yeo merged commit 1a69e0f into swiftlang:release/6.4.x Jun 9, 2026
24 checks passed
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