Skip to content

perf(editor): eliminate two-way controller bouncing and full-string comparisons in QueryaCodeEditor #1352

Closed

Description

@ZhuchkaTriplesix

Summary

In lib/core/editor/querya_code_editor.dart (lines 103–127, 181–185):
When an external controller is provided (e.g. from SqlQueryTabSession), QueryaCodeEditor instantiates an internal _highlightController (QueryaHighlightController) and wires up two-way listeners:

  • external.addListener(_syncFromExternal)
  • _highlightController.addListener(_syncToExternal)

Both callbacks perform full string comparisons:

if (external.text == highlight.text && external.selection == highlight.selection) {
  return;
}

Whenever the user types a single character:

  1. _highlightController notifies listeners.
  2. _syncToExternal runs and compares external.text == highlight.text (full string comparison of the entire document).
  3. If unequal, external.value = highlight.value.
  4. external notifies its listeners.
  5. _syncFromExternal runs and compares external.text == highlight.text again.

In medium to large SQL scripts (e.g. 50–500 KB), typing a single character triggers repeated multi-kilobyte string comparisons on the main UI thread.

Proposed Solution

  1. Allow QueryaCodeEditor to share the controller directly or allow SqlQueryTabSession to create a QueryaHighlightController directly.
  2. If two-way sync is retained for plain external controllers, track version/revision tokens or listen directly without comparing entire document strings on every keystroke.

Acceptance Criteria

  • No full-document string equality checks (external.text == highlight.text) on every keystroke in QueryaCodeEditor.
  • Synchronization between SqlQueryTabSession.controller and the editor remains consistent without text loss or cursor jumping.

Activity

  1. added
    editorCode/SQL editor
    performanceTheme parser epic label: performance
    coreCore library logic and services
    P3Low priority / Polish & Enhancements
    on Oct 10, 2026
  2. ZhuchkaTriplesix commented on Oct 11, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Resolved in #1467. Eliminated redundant text listener registration when onChanged is null and optimized _onTextChanged to use O(1) reference identity and length differential checks instead of repeated full-document string comparisons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low priority / Polish & EnhancementscoreCore library logic and serviceseditorCode/SQL editorperformanceTheme parser epic label: performance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions