Skip to content

Rework the cleanup a little bit so that we avoid the atomic boolean #761

Merged
ktoso merged 1 commit into
swiftlang:mainfrom
ktoso:ktoso/cleanup-atomic-field-updater
May 20, 2026
Merged

Rework the cleanup a little bit so that we avoid the atomic boolean #761
ktoso merged 1 commit into
swiftlang:mainfrom
ktoso:ktoso/cleanup-atomic-field-updater

Conversation

@ktoso
Copy link
Copy Markdown
Collaborator

@ktoso ktoso commented May 20, 2026

The atomic boolean was one extra heap allocation which we now avoid --
we just create one cleanup and inside it have an int, rather than
creating the Bool separately and passing it to the cleanup. AFAICS this
will avoid one alloc, which isn't much, but can add up since we do it
for every wrapped swift object.

This keeps semantics added by @sidepelican in #760 just avoids the one heap alloc per SwiftInstance

The atomic boolean was one extra heap allocation which we now avoid --
we just create one cleanup and inside it have an int, rather than
creating the Bool separately and passing it to the cleanup. AFAICS this
will avoid one alloc, which isn't much, but can add up since we do it
for every wrapped swift object.

This keeps semantics added by @sidepelican in
swiftlang#760 just avoids the one
heap alloc per SwiftInstance
private final long selfPointer;

/** Used to track additional state of the underlying object, e.g. if it was explicitly destroyed. */
private final AtomicBoolean $state$destroyed = new AtomicBoolean(false);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alloc we're removing; instead we have the Cleanup as we did before; alloc it early, but then inside the Cleanup we have no other heap objects -- just the int.

@ktoso ktoso merged commit 58fbf19 into swiftlang:main May 20, 2026
73 checks passed
@ktoso ktoso deleted the ktoso/cleanup-atomic-field-updater branch May 20, 2026 13:04
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