Skip to content

fix: prevent unnecessary histogram rerender - #3749

Open
knudtty wants to merge 7 commits into
mainfrom
aaron/prevent-unnecessary-histogram-rerender
Open

knudtty wants to merge 7 commits into
mainfrom
aaron/prevent-unnecessary-histogram-rerender

Conversation

@knudtty

@knudtty knudtty commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Summary

The search histogram was rerendering on unnecessary operations, like adding a column or adding an alias. This fixes that.

Screenshots or video

Before

export-1795209359104.mp4

After

export-1795209486556.mp4

References

  • Linear Issue: Closes HDX-6134

@knudtty
knudtty requested a review from a team as a code owner November 20, 2026 21:18
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 23, 2026 3:11pm UTC
hyperdx-storybook Ready Ready Preview Nov 23, 2026 3:11pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 39998be

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Additional context: spans packages but only 92 prod lines — under the 100-line cross-layer bar

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 3
  • Production lines changed: 92 (+ 60 in test files, excluded from tier calculation)
  • Branch: aaron/prevent-unnecessary-histogram-rerender
  • Author: knudtty

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 108 in total (1.13%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

Comment thread packages/app/src/DBSearchPage.tsx Outdated
setValue('orderBy', nextOrderBy);
setSearchedConfig({ select, orderBy: nextOrderBy });
} else {
setSearchedConfig({ select });

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.

🔴 P1 — Toggling a column now throws away the user's unsubmitted where text and filters

setSearchedConfig({ select }) changes searchedConfig, which fires the URL→form sync effect (DBSearchPage.tsx:1321-1334). That effect calls reset() with the searched where/filters/orderBy. Before this PR, onSubmit() submitted the draft where/filters along with the column. Now any typed but unsubmitted query is silently reset. A filter click still waiting in the 1s debouncedSubmit (handleSetFilters, :1469) also gets reset before it fires. Fix: when only select changes, skip the reset, or set select without the reset, or have onSubmit take a skipTimeResolve flag instead of bypassing it.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

2 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 1 P3

None could be anchored to changed lines; they are listed below. 1 P3 folded at the bottom.

Findings outside the changed lines

  • 🟡 P2 packages/app/src/DBSearchPage.tsx:2249 — The trace Duration heatmap still refetches when a table column changes → For trace sources, the heatmap mode of TraceRedMetricsChart (TraceRedMetricsChart.tsx:114-128) takes the place of the histogram. It is built from traceHeatmapChartConfig, which still passes the full aliasWith. Adding or removing an aliased column changes with, and with is part of the ['heatmap', minMaxConfig] / ['heatmap_bucket', …] query keys in DBHeatmapChart/useHeatmapData.ts, so the heatmap still refetches. The select gets overridden, so with is the only cause. Fix: build with here with the same getReferencedWithClauses(aliasWith, …) call the histogram uses. Even better, compute the referenced clauses once and share them between both configs.
🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/app/src/DBSearchPage.tsx:2020 — The new search-page behaviours have no tests, and the ChartUtils test doesn't cover the real regression risk → Nothing tests the two behaviours this PR adds: resolveTimeRange (a column toggle keeps searchedTimeRange unless the time input was edited or live tail is on), and the histogram config keeping its with and query key when select changes. The new ChartUtils test only checks eventTableSelect: undefined. That test would still pass if DBTimeChart's drill-down started reading from queriedConfig, which would drop select from "View events" URLs. Add a test that the histogram's "View events" URL still contains the table select (DBTimeChart.tsx:953 reads the unconverted config). Also add a DBSearchPage-level test that toggling a column leaves the histogram's query key unchanged.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 475 passed • 1 skipped • 1189s

Status Count
✅ Passed 475
❌ Failed 0
⚠️ Flaky 10
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

Comment thread packages/app/src/DBSearchPage.tsx Outdated
onSubmit();
// Keep the current time range: re-resolving a relative range would
// refetch the histogram for a column change.
onSubmit({ resolveTimeRange: false });

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.

🟡 P2 — Toggling a column now submits the drafted query but not the drafted time range

toggleColumn still runs handleSubmit, so any unsubmitted edits to the where/filters fields get applied. With resolveTimeRange: false, a range the user typed into the time input does not get applied. The result is a half-applied search: the time input shows a range that doesn't match the table or histogram. One fix is to skip onSearch only when displayedTimeInputValue still matches the searched range. The other is to also skip the draft where/filters in this path, setting only select/orderBy via setSearchedConfig.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. This is a focused, well-commented change. The core mechanism is sound: chartConfig carries no with field (buildSearchChartConfig never sets one), so the JSON.stringify haystack in getReferencedWithClauses is not polluted by alias SQL; every histogram-used, alias-bearing field (where, filters, timestampValueExpression, body, sample-weight, groupBy) remains in the matched text, so the filter cannot under-include for the real call path. Original clause order is preserved and transitive dependencies are resolved, so dropping unused WITH clauses does not change query results. The appliedTimeInputValue/isTimeInputEdited state is robust: the bare setDisplayedTimeInputValue is only wired to user typing, while every applied-range write flows through setAppliedTimeInput, so isTimeInputEdited is true exactly when an edit is pending.

🟡 P2 -- recommended

  • packages/app/src/DBSearchPage.tsx:2020 -- The new onSubmit({ resolveTimeRange: !!isLive || isTimeInputEdited }) gating and the appliedTimeInputValue/isTimeInputEdited sync have no test at any level, so a future regression that re-resolves (or fails to re-resolve) the time range on column toggle would go uncaught.
    • Fix: Add a DBSearchPage test asserting that toggling a column with an unedited non-live range calls onSubmit with resolveTimeRange=false, while an edited input or live tail resolves.
    • testing
  • packages/app/src/__tests__/DBSearchPageQueryKey.test.tsx:74 -- No test exercises the PR's core behavior: that adding/removing a table column or an alias leaves the histogram query key unchanged; the added unit tests cover convertToTimeChartConfig and getReferencedWithClauses only in isolation.
    • Fix: Add a case that renders the histogram config, mutates searchedConfig.select and the alias map, and asserts the DBTimeChart query key is stable.
    • testing, kieran-typescript
🔵 P3 nitpicks (4)
  • packages/common-utils/src/__tests__/utils.test.ts:3389 -- The new getReferencedWithClauses tests miss the behavior-defining edges: a clause referenced only via blanked select/orderBy being dropped (the actual histogram use case), substring over-inclusion, and an empty-string clause name that haystack.includes('') always keeps.
    • Fix: Add cases for the select/orderBy-only drop, a substring collision, and an empty-name clause.
    • testing, performance
  • packages/app/src/DBSearchPage.tsx:2184 -- getReferencedWithClauses matches alias names against the full JSON.stringify of the config, whose structural keys (source, from, where) can collide with plausible alias names and keep a clause that is not actually referenced, partially defeating the refetch avoidance (degrades to prior behavior, never incorrect).
    • Fix: Match against the concrete expression strings (where/filters/timestamp/body/sample-weight/groupBy) rather than the whole serialized config.
    • maintainability, kieran-typescript
  • packages/common-utils/src/core/utils.ts:1721 -- The transitive expansion only appends clause.sql?.sql, so a future caller passing subquery clauses (isSubquery: true, no sql) would skip traversal of that clause's body and could under-include transitively referenced aliases; not reachable today since the only caller passes aliasMapToWithClauses output.
    • Fix: Document that the function assumes expression (sql-bearing) clauses, or handle subquery bodies before exporting it for broader use.
    • kieran-typescript
  • packages/app/src/DBSearchPage.tsx:1312 -- setAppliedTimeInput writes both displayed and applied state but is passed into useNewTimeQuery under the prop name setDisplayedTimeInputValue, hiding from the hook that this callback also commits the applied range that drives isTimeInputEdited.
    • Fix: Rename to convey the commit semantics and add a one-line note at the call site.

Reviewers (5): testing, maintainability, performance, project-standards, kieran-typescript.

Coverage: The correctness and julik-frontend-races reviewers were dispatched but had not returned at synthesis time; the orchestrator independently verified the under/over-inclusion safety, clause-ordering preservation, applied/displayed state sync, and useCallback dependency completeness, finding no correctness or race defects. The changeset correctly lists @hyperdx/app and @hyperdx/common-utils as patch, and TypeScript typing of the new code is clean (clause.sql?.sql ?? '' is correctly guarded; dependency arrays are complete).

Testing gaps:

  • DBSearchPage time-input gating (resolveTimeRange, isTimeInputEdited) has no unit or integration coverage.
  • No end-to-end assertion that a column toggle or alias add keeps the histogram query key stable.
  • getReferencedWithClauses select/orderBy-only drop, substring over-inclusion, and empty-name cases are uncovered.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

Comment thread packages/app/src/DBSearchPage.tsx Resolved
Comment thread packages/app/src/DBSearchPage.tsx Resolved
Comment thread packages/app/src/DBSearchPage.tsx Resolved
Comment thread packages/app/src/DBSearchPage.tsx Resolved
// Everything but the table's select and sort can reference an alias,
// including the body, timestamp and sample-weight expressions.
with: getReferencedWithClauses(aliasWith, [
JSON.stringify({ ...chartConfig, select: '', orderBy: '' }),

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.

🟡 P2 — Alias matching runs over the whole config JSON, so many aliases are always kept and the histogram still refetches

getReferencedWithClauses checks whether an alias name appears anywhere in JSON.stringify({...chartConfig, select:'', orderBy:''}) (packages/common-utils/src/core/searchChartConfig.ts). That string always contains the field names (timestampValueExpression, databaseName/tableName, displayType, source, connection, where, select, orderBy, and bodyExpression on log sources) plus the hex ids for the source and connection. So an alias named time, name, type, table, source, body, value or search, or any one-letter alias such as c or a, is always kept. Toggling that column still changes the query key, and the histogram refetches anyway. Fix: build the text only from the parts that can actually reference an alias (where, filters, groupBy, implicitColumnExpression, bodyExpression, timestampValueExpression, the sample-weight expression), and match on identifier boundaries (e.g. (?<![\w.])name(?!\w)) instead of includes.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 69f52c02 Deployed Nov 23, 2026 by vercel[bot]
Preview – hyperdx-storybook — 69f52c02 Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant