Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

fix(grid): every result grid leaks (extension-method listener on PiiMaskingController is never removed); ~5 MB per run

未關閉
#1,555 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
dart, flutter

研究方向

Start with the listener registration and disposal in lib/features/workspace/result_grid_view.dart, then read the extension handlers in lib/features/workspace/grid/grid_pii_masking.dart and inspect the horizontal scroll listener pair. Add a guard under test/guards/ and a widget test that disposes VirtualResultGrid and checks PiiMaskingController.instance.hasListeners; run those tests. Done means listeners are removed and the guard catches extension method tear-offs used in listener pairs.

由索引模型根據 Issue 內容生成。

描述

bug data-grid P1 performance stability
Problem

Every result grid that is ever shown is kept in memory for the rest of the session, together with its whole result set and its widget / render / semantics tree. Each query run and each closed tab leaks one grid.

Cause: _VirtualResultGridState registers _onPiiMaskingChanged as a listener on the app-wide singleton PiiMaskingController.instance (lib/features/workspace/result_grid_view.dart:167) and removes it in dispose() (:392), but _onPiiMaskingChanged is declared in an extension _GridPiiMasking on _VirtualResultGridState (lib/features/workspace/grid/grid_pii_masking.dart:34). In Dart, tearing off an extension method creates a new closure each time and two such closures are not equal, so removeListener(_onPiiMaskingChanged) does not find the one that addListener(_onPiiMaskingChanged) stored. The listener stays in the singleton's list and keeps the state alive forever: state -> widget -> CompactResultDataset / rows -> element tree -> render objects -> semantics.

Minimal reproduction of the language behavior:

class Owner { void inClass() {} void reg(Notifier n){ n.add(inClass); n.add(ext);} void unreg(Notifier n){ n.remove(inClass); n.remove(ext);} }
extension E on Owner { void ext() {} }
// after reg + unreg: 1 listener is left (the extension tear-off); `o.inClass == o.inClass` is true, `o.ext == o.ext` is false
Measurements

Profile build of dev 0.4.22+5, app benchmark harness, Dart heap after a forced full GC (getAllocationProfile(gc: true)), heavySql = 5000 rows x 20 columns, retaining paths from the VM service:

Re-running a query 6 more times in the same tab

live _VirtualResultGridState live CompactResultDataset Dart heap
after 1 result 1 1 62 MB
after 6 re-runs 6 6 92.5 MB (+5 MB per run)

Opening a tab, running the query, closing the tab (confirming "Discard & Close"), 4 times

baseline after 4 cycles
mounted QueryEditorTab / ResultsTab 1 1
live QueryEditorTab instances 2 6
live ResultsTab 2 6
live VirtualResultGrid / _VirtualResultGridState 1 5
live CompactResultDataset 1 5
live FocusNode 105 235
live AnimationController 147 323
Dart heap 58 MB 87-90 MB

Retaining path of every leaked grid state (identical for all, 6 elements):

_VirtualResultGridState <- Context.0[] <- _Closure <- _List.N[] <- PiiMaskingController._listeners <- (static field PiiMaskingController.instance)

and of the leaked CompactResultDataset: _LazyDatasetRowList.dataset <- ResultsTab.rows <- _ResultsTabState._widget ... <- _VirtualResultGridState._focusNode ... <- PiiMaskingController._listeners.

A session of 100 queries on a 5000 x 20 result leaks on the order of 500 MB of Dart heap, more for larger results and a lot more for a result with a raised row cap.

Solution
  • Declare _onPiiMaskingChanged (and _onHorizontalScroll, which has the same shape) inside the State class instead of an extension, or keep the listener in a field: late final VoidCallback _piiListener = _onPiiMaskingChanged; and use that field for both addListener and removeListener.
  • A scan of lib/ found exactly these two addListener / removeListener pairs whose handler is an extension method; _onHorizontalScroll is attached to a controller that dispose() discards, so it is harmless in practice, but should be fixed the same way.
  • Add a guard test in test/guards/ that fails when the argument of addListener( / removeListener( is a method declared in an extension (the regex scan used for this report is enough).
Acceptance
  • PiiMaskingController.instance has no listeners after a VirtualResultGrid is disposed (widget test: pump the grid, remove it, assert hasListeners == false).
  • 6 re-runs of the same query in one tab leave 1 live _VirtualResultGridState (check with a leak test or leak_tracker).
  • Closing a tab releases QueryEditorTab, ResultsTab, the grid and its dataset.
  • Heap after N re-runs is flat in the app benchmark (add a leak_rerun scenario that prints live-instance counts after GC).

Related: #1549, #1552 (memory of the result path).

主要語言
Dart
星號
23
分支
1
平均合併
31 分鐘
30 天內合併 PR
570

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

QueryaHub/Querya-Desktop 的其他 Issue

查看 QueryaHub/Querya-Desktop 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。