Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Single Text Storage For Documents #1740

Merged

Conversation

thecoolwinter
Copy link
Collaborator

Description

Right now, CodeFileView is reevaluated each keystroke, causing a severe lag on large files. On top of being reevaluated it does a string compare on CodeFileDocument.content, which causes a hang for large files that then need to be compared character by character. This comparison isn't consistent, and is up to SwiftUI's heuristic for choosing when to compare the published variable.

This PR changes CodeFileDocument to use a non-published NSTextStorage object to store the document's contents. This means we have a single copy of the document across the entire app. Before, there was a copy stored in the text view's text storage, as well as in the code file document's content string. This also makes editing more efficient, as the contents of the document aren't copied each keystroke from the text view's text storage to the document's Swift String. Finally, SwiftUI will not attempt to compare views using this property as it's not published and the CodeFileView has a stable identifier.

This also enables listening to changes in the document via a new combine object that publishes notifications for changes in the content and cursor position changes. These are used now to update the auto-save timer rather than listening for changes in the content publisher.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Copy link
Member

@activcoding activcoding left a comment

Choose a reason for hiding this comment

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

Good to Go. Great Job!

@thecoolwinter thecoolwinter merged commit e17584e into CodeEditApp:main Jun 1, 2024
2 checks passed
@thecoolwinter thecoolwinter deleted the fix/editor-evaluation-perf branch June 1, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐞 CodeFileView Reevaluated Every Keystroke
3 participants