Skip to content

Conversation

@DPrakashh
Copy link

Following the discussion in #1597, this PR migrates the documents dictionary in DocumentManager from a DispatchQueue to a ThreadSafeBox.

This approach was chosen to keep the DocumentManager APIs synchronous while still ensuring thread safety.

Changes:
1-Replaced DispatchQueue with ThreadSafeBox<[DocumentURI: Document]>.
2-Updated all call sites (open, close, edit, etc.) to use .withLock.
3-Marked the Document class as @unchecked Sendable to satisfy ThreadSafeBox requirements.
4-Cleaned up imports (removed Dispatch, added SwiftExtensions).

Note:Verified locally with swift test; all relevant tests passed.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Nice. That looks easier than I imagined.

Replaces DispatchQueue with ThreadSafeBox, relaxes T: Sendable constraints, and removes @unchecked Sendable from Document.
@DPrakashh
Copy link
Author

DPrakashh commented Dec 21, 2025

I have pushed the refactored threading model as discussed. The implementation now uses a modernised ThreadSafeBox to manage the document registry.

Key Technical Highlights:
1-Locking Strategy: Replaced the serial DispatchQueue in DocumentManager with ThreadSafeBox. This provides lower-latency synchronization for document lookups and edits.
2-Type Safety: Relaxed ThreadSafeBox constraints to support non-Sendable storage while enforcing Sendable on the withLock return value. This allowed me to remove @unchecked Sendable from the Document class.
3-Compiler Satisfaction: Used nonisolated(unsafe) for internal box storage, manually protected by NSLock, to satisfy Swift 6 strict concurrency checks.

Verification: Verified the build and successfully ran "swift test".

@DPrakashh DPrakashh requested a review from ahoppen December 21, 2025 14:04
@DPrakashh
Copy link
Author

DPrakashh commented Dec 22, 2025

Hi @ahoppen,
I wanted to check if it's alright if I contribute from my college-linked account
Link - account starting with Mark 3? I'm using this account specifically to access GitHub Education benefits during my studies, and I'd like to keep my academic work on this profile until I graduate.

I'll ensure that my name and commit identity remain consistent so you can still track my progress from Mark 2 easily. Does this switch work for you? - as my account got approved for education pack of GitHub😊

Thanks!

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Nice. Looks good to me 👍🏽

@ahoppen
Copy link
Member

ahoppen commented Dec 22, 2025

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented Dec 22, 2025

I wanted to check if it's alright if I contribute from my college-linked account

Absolutely! Contribute with whichever GitHub account you prefer.

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