Skip to content

Skip editor validation when the parse result can't have changed#36

Draft
Edwinexd wants to merge 1 commit into
masterfrom
fix/issue-19-battery-usage
Draft

Skip editor validation when the parse result can't have changed#36
Edwinexd wants to merge 1 commit into
masterfrom
fix/issue-19-battery-usage

Conversation

@Edwinexd

@Edwinexd Edwinexd commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Addresses part of #19 (battery usage).

The live "validate on change" effect ran on every keystroke, calling validateStatements (SQLite prepares/parses via iterateStatements, Postgres runs EXPLAIN) and, in RA mode, raToSQLgetColumnNamesdb.prepare(). No debounce, no memoization. That per-keystroke parsing is the main CPU/battery cost while typing.

Instead of a blanket timer, skip the engine call only when the result provably can't have changed since the last validation:

  • Exact repeat: same query string as last validation (effect re-fired for an unrelated dependency) reuses the previous result.
  • Syntax error + append: a real syntax error fails at the first bad token, so appending further whitespace-separated tokens after an already-validated syntax error leaves that earlier failure unchanged. The whitespace check prevents appended characters from merging into the failing token. Excludes incomplete-input errors (appending may complete them) and semantic errors like missing table/column (appending changes name resolution).

Error classification covers both engines:

SQLite Postgres (EXPLAIN)
incomplete incomplete input syntax error at end of input
syntax near "X": syntax error syntax error at or near "X"
semantic no such table: X relation "x" does not exist

Persistence (localStorage + written-questions tracking) is split into its own effect so it stays immediate; only the engine validation is skipped.

RA mode keeps only the exact-repeat guard since its error shapes don't fit the append invariant.

Existing suite passes (249 tests), tsc and eslint clean.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sql-validator with  Cloudflare Pages  Cloudflare Pages

Latest commit: e471245
Status: ✅  Deploy successful!
Preview URL: https://11180a35.dsv-db-sql-validator.pages.dev
Branch Preview URL: https://fix-issue-19-battery-usage.dsv-db-sql-validator.pages.dev

View logs

@Edwinexd Edwinexd marked this pull request as draft July 6, 2026 12:25
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