Skip to content

perf: optimize SQL editor typing performance#16

Merged
datlechin merged 16 commits intomainfrom
fix/sql-editor-performance-optimization
Jan 5, 2026
Merged

perf: optimize SQL editor typing performance#16
datlechin merged 16 commits intomainfrom
fix/sql-editor-performance-optimization

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

Fix SQL editor typing lag by implementing two key optimizations.

Changes

1. SQLContextAnalyzer.swift - Pre-compile regex patterns

Pre-compiled 21 regex patterns as static properties instead of compiling on every autocomplete call:

  • 17 clause detection patterns
  • 4 string/comment removal patterns

Impact: Eliminates ~21 regex compilations per autocomplete trigger.

2. EditorTextView.swift - Smart view invalidation

Replaced full view redraw with smart line-based invalidation:

  • Track the last cursor line position
  • Only invalidate current and previous line regions
  • Skip redraw entirely if cursor stays on the same line

Impact: Reduces GPU work from full-view redraw to only 1-2 line regions.

Testing

  • Build succeeds
  • Manual testing: Type rapidly in SQL editor - should feel responsive without lag

- Pre-compile 21 regex patterns in SQLContextAnalyzer as static properties
  (eliminates regex compilation on every autocomplete call)
- Add smart view invalidation in EditorTextView to only redraw affected
  line regions instead of full view on every keystroke
Copilot AI review requested due to automatic review settings January 5, 2026 12:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes SQL editor typing performance by pre-compiling regex patterns and implementing smart view invalidation to reduce unnecessary redraws.

  • Pre-compiled 21 regex patterns as static properties in SQLContextAnalyzer to eliminate repeated compilation overhead
  • Implemented line-based invalidation in EditorTextView to redraw only affected line regions instead of the full view
  • Added ALTER TABLE column context detection with new alterTableColumn clause type

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
TablePro/Views/Editor/EditorTextView.swift Implements smart line-based invalidation with cursor tracking to minimize redraw regions, replacing full view redraws
TablePro/Core/Autocomplete/SQLContextAnalyzer.swift Pre-compiles 21 regex patterns as static properties and adds ALTER TABLE context extraction for improved autocomplete performance

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift
datlechin and others added 2 commits January 5, 2026 20:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
datlechin and others added 3 commits January 5, 2026 21:13
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift Outdated
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift Outdated
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift Outdated
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
datlechin and others added 4 commits January 5, 2026 21:22
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TablePro/Views/Editor/EditorTextView.swift
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift
Comment thread TablePro/Views/Editor/EditorTextView.swift
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Views/Editor/EditorTextView.swift Outdated
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift Outdated
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift
Comment thread TablePro/Core/Autocomplete/SQLContextAnalyzer.swift
datlechin and others added 5 commits January 5, 2026 21:31
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
@datlechin datlechin merged commit 2ae4b01 into main Jan 5, 2026
@datlechin datlechin deleted the fix/sql-editor-performance-optimization branch January 5, 2026 14:36
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