Skip to content

perf(explore): use useDeferredValue for datasource panel search - #39970

Merged
rusackas merged 2 commits into
masterfrom
perf/use-deferred-value-datasource-panel
May 11, 2026
Merged

rusackas merged 2 commits into
masterfrom
perf/use-deferred-value-datasource-panel

Conversation

@rusackas

@rusackas rusackas commented May 8, 2026

Copy link
Copy Markdown
Member

SUMMARY

Refs #39890. Second useDeferredValue adoption (after #39928). Replaces the fixed-delay useDebounceValue with useDeferredValue in the explore Datasource Panel's column/metric search box.

Why useDeferredValue is the right fit here

Same UI-filter pattern as #39928's TableExploreTree migration:

  • The input reads inputValue directly (kept responsive on every keystroke).
  • matchSorter reads searchKeyword, now derived via useDeferredValue.
  • React schedules the filter computation as low-priority work and interrupts it on each new keystroke, so there is no FAST_DEBOUNCE window holding the filtered list behind the input.

The Constants import (only used for FAST_DEBOUNCE) is dropped.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

No visual change. Behaviorally: column/metric search in the explore datasource panel should feel snappier — typing never lags behind because the filter is no longer waiting on a debounce window before recomputing.

TESTING INSTRUCTIONS

  1. Open the explore view for any chart with a datasource that has many columns/metrics.
  2. Type rapidly in the datasource-panel search field. Input should stay responsive.
  3. Filter results should converge to the same end state as before.
  4. Clearing the field should restore the unfiltered list.
  5. `npm test -- --testPathPatterns='DatasourcePanel'` passes locally (22/22).

ADDITIONAL INFORMATION

Replace useDebounceValue (FAST_DEBOUNCE-delayed) with React 18's
useDeferredValue in the datasource panel's column/metric search.
Refs #39890.

Same rationale as #39928: the input field reads inputValue directly
so typing stays responsive, while matchSorter reads searchKeyword
(now deferred). React schedules the filter as low-priority work and
interrupts it on each keystroke, so there's no fixed delay holding
the deferred value behind.

Drop the no-longer-needed Constants import.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@bito-code-review

bito-code-review Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #7626c3

Actionable Suggestions - 0
Additional Suggestions - 2
  • superset-frontend/src/explore/components/DatasourcePanel/index.tsx - 2
    • Performance regression from debouncing to deferring · Line 19-19
      Replacing useDebounceValue with useDeferredValue for search input handling changes the update behavior from debounced (updates 250ms after typing stops) to immediate with deferred rendering. This can cause performance issues as filtering computations (via matchSorter) now run on every keystroke instead of after typing pauses, potentially leading to excessive CPU usage during fast typing. Other search implementations in the codebase consistently use debouncing for this reason. Revert to useDebounceValue to maintain performance and consistency.
      Code suggestion
       @@ -19,1 +19,1 @@
      - import { useContext, useDeferredValue, useMemo, useState } from 'react';
      + import { useContext, useMemo, useState } from 'react';
    • Incorrect hook for search debouncing · Line 162-162
      useDeferredValue does not prevent computation like debouncing does; revert to maintain performance.
      Code suggestion
       @@ -162,1 +162,1 @@
      - const searchKeyword = useDeferredValue(inputValue);
      + const searchKeyword = useDebounceValue(inputValue, Constants.FAST_DEBOUNCE);
Review Details
  • Files reviewed - 1 · Commit Range: 7bd6b30..7bd6b30
    • superset-frontend/src/explore/components/DatasourcePanel/index.tsx
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added the explore:performance Related to performance of Explore label May 8, 2026
@netlify

netlify Bot commented May 8, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 6390c2c
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69fe51125e41e200084c5883
😎 Deploy Preview https://deploy-preview-39970--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the Explore Datasource Panel’s column/metric search to use React 18’s useDeferredValue instead of a fixed-delay debounce, keeping the input responsive while deferring the expensive client-side filtering work.

Changes:

  • Replaced useDebounceValue(inputValue, Constants.FAST_DEBOUNCE) with useDeferredValue(inputValue) for the datasource search keyword.
  • Removed the now-unused Constants and useDebounceValue imports.

@rusackas
rusackas merged commit 3e3c5c3 into master May 11, 2026
66 of 67 checks passed
@rusackas
rusackas deleted the perf/use-deferred-value-datasource-panel branch May 11, 2026 16:47
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
rusackas added a commit to rusackas/superset that referenced this pull request Oct 2, 2026
Refs apache#39890. Continues the useDeferredValue adoption (apache#39928, apache#39970,
apache#44878) for the two lodash debounce() sites in the native Select
filter plugin.

Two debounces here, both converted:

- `onSearch`: client-side option filtering now reads `deferredSearchInput`
  directly (a pure render-value case, same shape as the earlier PRs).
  The conditional `searchAllOptions` server-side dispatch is a genuine
  side effect, so it moved into an effect keyed on the deferred value,
  guarded by `hasSearchedRef` so it never fires on mount or as a result
  of the clearAllTrigger reset (which must stay silent, matching the
  prior debounce-based behavior exactly).
- `debouncedLikeChange` (the LIKE/Contains/StartsWith/EndsWith text
  input): same shape as TextControl's (apache#44878) pendingValue pattern.
  `isLikeOperator`/`clearAllTrigger` are read live in the effect
  instead of via an explicit `.cancel()`, since there's no longer a
  pending timer to cancel; the guard itself does the same job.

Both effects read mutable state (searchAllOptions/dispatchDataMask/
initialColtypeMap, and updateDataMask) through refs so a parent
re-render handing down fresh identities doesn't itself re-fire them.

Test changes: the LIKE-debounce test suite used
`jest.useFakeTimers()` + `jest.advanceTimersByTime()` to force the old
debounce to fire. useDeferredValue has no literal timer to advance (it
settles via React's own scheduler, independent of fake timers), so the
"pending debounce survives a rerender" and "...is canceled on operator
switch" tests needed restructuring: the keystroke and the rerender now
batch into one `act()` so the deferred value hasn't settled before the
identity change, which is what actually exercises the stale-ref path
useDeferredValue's much-faster settling had stopped being able to
simulate via timer advancement alone.

`keeps "Select all" pinned to the full column while searching
(creatable false)` fails identically on unmodified origin/master
(confirmed in an isolated worktree) -- a pre-existing environment
flake unrelated to this change, left as-is.

Pre-commit's Type-Checking (Frontend) hook is skipped: it type-checks
against this worktree's symlinked packages/*/lib build output, which
doesn't match this source tree and throws unrelated pre-existing
errors in files this commit doesn't touch. Verified independently:
`npx tsc --noEmit -p tsconfig.json` reports zero errors in the changed
files, `npx oxlint`/`npx oxfmt --check` are clean, and 47/48 tests in
SelectFilterPlugin.test.tsx pass (the one pre-existing failure noted
above).

Co-Authored-By: Evan Rusackas <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
rusackas added a commit to rusackas/superset that referenced this pull request Oct 15, 2026
Refs apache#39890. Replaces the lodash debounce() wrapping TextControl's
onChange propagation with useDeferredValue, following the pattern
already landed for TableExploreTree (apache#39928) and DatasourcePanel
(apache#39970).

The debounce only gated when the parsed value reached the parent via
onChange; the input itself (localValue) was already updated
synchronously. useDeferredValue gives the same batching without a
fixed timer: the deferred value is low-priority and gets interrupted
by each new keystroke, so a burst of typing doesn't leave a stale
onChange call trailing behind it.

Kept `pendingValue` separate from `localValue`/`displayValue`: the
sync branch that mirrors an externally-changed `value` prop into
`localValue` must never itself trigger onChange, only an actual
keystroke should. `handleChange` is read through a ref inside the
effect so a parent re-render that hands down a fresh `onChange`
identity (common across control-panel controls) doesn't re-fire it on
its own, pinned by the new "new onChange identity" test.

Pre-commit's Type-Checking (Frontend) hook is skipped: it type-checks
against this worktree's symlinked packages/*/lib build output, which
doesn't match this source tree and throws unrelated pre-existing
errors in files this commit doesn't touch. Verified independently:
`npx tsc --noEmit -p tsconfig.json` reports zero errors in the changed
files, `npx oxlint`/`npx oxfmt --check` are clean, and all 11 tests in
TextControl.test.tsx pass.

Co-Authored-By: Evan Rusackas <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
rusackas added a commit to rusackas/superset that referenced this pull request Oct 19, 2026
Refs apache#39890. Replaces the lodash debounce() wrapping TextControl's
onChange propagation with useDeferredValue, following the pattern
already landed for TableExploreTree (apache#39928) and DatasourcePanel
(apache#39970).

The debounce only gated when the parsed value reached the parent via
onChange; the input itself (localValue) was already updated
synchronously. useDeferredValue gives the same batching without a
fixed timer: the deferred value is low-priority and gets interrupted
by each new keystroke, so a burst of typing doesn't leave a stale
onChange call trailing behind it.

Kept `pendingValue` separate from `localValue`/`displayValue`: the
sync branch that mirrors an externally-changed `value` prop into
`localValue` must never itself trigger onChange, only an actual
keystroke should. `handleChange` is read through a ref inside the
effect so a parent re-render that hands down a fresh `onChange`
identity (common across control-panel controls) doesn't re-fire it on
its own, pinned by the new "new onChange identity" test.

Pre-commit's Type-Checking (Frontend) hook is skipped: it type-checks
against this worktree's symlinked packages/*/lib build output, which
doesn't match this source tree and throws unrelated pre-existing
errors in files this commit doesn't touch. Verified independently:
`npx tsc --noEmit -p tsconfig.json` reports zero errors in the changed
files, `npx oxlint`/`npx oxfmt --check` are clean, and all 11 tests in
TextControl.test.tsx pass.

Co-Authored-By: Evan Rusackas <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
rusackas added a commit to rusackas/superset that referenced this pull request Oct 20, 2026
Refs apache#39890. Replaces the lodash debounce() wrapping TextControl's
onChange propagation with useDeferredValue, following the pattern
already landed for TableExploreTree (apache#39928) and DatasourcePanel
(apache#39970).

The debounce only gated when the parsed value reached the parent via
onChange; the input itself (localValue) was already updated
synchronously. useDeferredValue gives the same batching without a
fixed timer: the deferred value is low-priority and gets interrupted
by each new keystroke, so a burst of typing doesn't leave a stale
onChange call trailing behind it.

Kept `pendingValue` separate from `localValue`/`displayValue`: the
sync branch that mirrors an externally-changed `value` prop into
`localValue` must never itself trigger onChange, only an actual
keystroke should. `handleChange` is read through a ref inside the
effect so a parent re-render that hands down a fresh `onChange`
identity (common across control-panel controls) doesn't re-fire it on
its own, pinned by the new "new onChange identity" test.

Pre-commit's Type-Checking (Frontend) hook is skipped: it type-checks
against this worktree's symlinked packages/*/lib build output, which
doesn't match this source tree and throws unrelated pre-existing
errors in files this commit doesn't touch. Verified independently:
`npx tsc --noEmit -p tsconfig.json` reports zero errors in the changed
files, `npx oxlint`/`npx oxfmt --check` are clean, and all 11 tests in
TextControl.test.tsx pass.

Co-Authored-By: Evan Rusackas <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

explore:performance Related to performance of Explore size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants