Feature request: live: allow pausing the notify triggers during bulk writes (e.g. pglite-sync applies) and refresh once on resume
メンテナーはふだん 1 日以内に返信
@tdrz がすでに取り組んでいます。
2026年11月2日 から。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- postgresql, typescript
- 領域
- databases
調査の方向性
Start with addNotifyTriggersToTables() in packages/pglite/src/live/index.ts, where the generated _notify_ trigger function body is created, and read the setup comment about triggers being added but never removed. Before any code, the open question is design: whether a GUC check, live.pause()/live.resume(), or both should be adopted, which the maintainers have not yet answered. Done means a maintainer-agreed design and tests showing that a bulk write with notifications suspended emits no notify, with one refresh on resume.
索引モデルが issue の本文から書いたものです。
説明
This was prepared by my AI tools (GLM 5.3, refined by Claude Fable 5.1). Applying it solved my performance issue but I must admit I could not have done this myself. So make of it what you want. I hope it helps others but also that I'm not spamming you with garbage.
Summary
The live extension's notify triggers fire unconditionally, so during bulk writes — in particular @electric-sql/pglite-sync applying a shape snapshot — every mounted live query re-runs back-to-back for the entire duration of the write. A supported way to pause notifications (and refresh once on resume) would remove this.
Current behaviour
addNotifyTriggersToTables() in packages/pglite/src/live/index.ts creates, per table a live query depends on, one function _notify_<schema_oid>_<table_oid>() that does PERFORM pg_notify('table_change__…', ''), attached as an AFTER INSERT OR UPDATE OR DELETE … FOR EACH STATEMENT trigger. There is no condition under which it stays silent. (As the comment in setup notes, the triggers are only ever added, never removed; tableNotifyTriggersAdded guarantees exactly one function per table.)
pglite-sync applies each batch in a transaction with SET LOCAL electric.syncing = true. Postgres de-duplicates identical notifications within a transaction, so after each commit every table written in that batch notifies once, and every live query reading any of those tables calls refresh().
refresh() is wrapped in debounceMutex, so a single query never has more than one run in flight plus one pending. That bounds it per query — but the net effect is that every mounted live query re-runs continuously for as long as the sync is applying, each run a full query through the same serialized execution queue the applies themselves use.
Impact
Our app: ~60 shapes, a navigation tree with up to a few hundred mounted live queries, a few hundred thousand rows on first sync or on a shape 409 re-snapshot. Unmodified, the notify traffic roughly doubled initial sync time, drove memory up noticeably and starved interactive reads until the sync settled.
Workaround we use
After boot (and periodically, because the functions are created lazily when a table gets its first live query) we rewrite the generated function bodies:
CREATE OR REPLACE FUNCTION "_notify_<s>_<t>"() RETURNS trigger AS $$
BEGIN
IF COALESCE(NULLIF(current_setting('electric.syncing', true), ''), 'false')::boolean THEN
RETURN NULL;
END IF;
PERFORM pg_notify('table_change__<s>__<t>', '');
RETURN NULL;
END $$ LANGUAGE plpgsql;
and when the sync reports up-to-date we fire one pg_notify per live channel so queries that were mounted during the sync pick up the applied data. It works, but it reaches into generated internals, couples live to pglite-sync's private GUC, and the settle round is easy to get wrong (without it, queries mounted mid-sync show empty results until the next real write).
Proposal
Keep live generic, but give bulk writers a supported way to suspend notifications:
- A GUC checked by the generated trigger function, e.g.
pglite.live_notify(default on). Any bulk writer canSET LOCAL pglite.live_notify = offinside its transaction — pglite-sync applies, imports,COPY-style loads. Since there is exactly one generated function per table, this is a one-line change inaddNotifyTriggersToTables()with no new bookkeeping. live.pause()/live.resume()on the namespace (or a transaction-scoped helper), whereresume()issues one notification per table written while paused, so live queries mounted mid-pause are refreshed exactly once instead of never.- pglite-sync uses (1) in its apply transaction and calls (2) when a batch ends up-to-date.
(1) alone removes the amplification; (2) is what makes the home-grown settle round unnecessary.
Happy to open a PR for (1) and the pglite-sync side if this direction is acceptable.
Environment
@electric-sql/pglite0.5.14,@electric-sql/pglite-sync0.6.15,@electric-sql/client1.5.28- PGlite in a web worker with IndexedDB persistence, Chrome on Linux
- 主要言語
- TypeScript
- スター
- 16.3k
- フォーク
- 474
- 平均マージ
- 23時間 53分
- マージ済み PR(30日)
- 53
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
electric-sql/pglite のほかの issue
-
Feature request: Nitro 3 support (`unwasm` export condition)再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
electric-sql/pglite#1120 · コメント 16 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
electric-sql/pglite#1200 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 54/100
electric-sql/pglite#1192 ·
メンテナーはふだん 1 日以内に返信
-
[BUG]: syncToFs() resolves immediately, without syncing, when another sync is already queued対応中かも @PrabalParihar が 11 日前に担当しました。 オープンbug
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
electric-sql/pglite#1191 ·
メンテナーはふだん 1 日以内に返信
-
pglite-socket: handleData copies the whole buffer for every chunk (quadratic time for large messages)対応中かも @benclmnt が 10 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
electric-sql/pglite#1181 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
electric-sql/pglite の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
langchain-ai/langchainjs#12239 ·
メンテナーはふだん 1 日以内に返信
-
Board view: the Monitoring column is always empty because compact issue rows drop displayStatusオープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
paperclipai/paperclip#21837 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
code-yeongyu/senpi#6813 ·
メンテナーはふだん 1 日以内に返信
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 93/100
lingdojo/kana-dojo#34169 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100