Skip to content

fix: prevent unnecessary histogram rerender - #3749

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

knudtty wants to merge 6 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 20, 2026 10:19pm UTC
hyperdx-storybook Ready Ready Preview Nov 20, 2026 10:19pm 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

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: 93 (+ 59 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

1 posted as inline comment(s) on the changed lines. 1 P3 folded at the bottom.

🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/app/src/components/Search/__tests__/histogramWith.test.ts:214 — Tests never use the input the page actually builds, and the new time-range skip on column toggle is untested → Each test passes short hand-written strings such as "service = 'api'". None passes the serialized chart config that DBSearchPage really builds, so the key-collision problem above would still pass. Add a case that builds the config with buildSearchChartConfig, then checks that an alias named e.g. name or time is dropped when nothing references it. Also add a test for the onSubmit({ resolveTimeRange: !!isLive || isTimeInputEdited }) path: toggling a column with the time input unchanged should leave from/to alone, and toggling after typing a new range should apply that range.

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 • 474 passed • 1 skipped • 1187s

Status Count
✅ Passed 474
❌ Failed 0
⚠️ Flaky 8
⏭️ 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.

The three core mechanisms were verified against the actual code by the correctness and adversarial reviewers: dropping eventTableSelect in convertToTimeChartConfig only affects the query key (the search-page "View events" link is built from the unconverted config prop in DBTimeChart, and the sole other converted-config path — the dashboard heatmap — never sets eventTableSelect); getReferencedWithClauses terminates and resolves transitive alias dependencies correctly; and the displayedTimeInputValue/appliedTimeInputValue state pair keeps the histogram and results table on the same searchedTimeRange.

🟡 P2 — recommended

  • packages/app/src/DBSearchPage.tsx:2020 — The PR's central behavior change — toggleColumn passing resolveTimeRange: !!isLive || isTimeInputEdited so a column/alias toggle does not re-resolve the time range (and the histogram does not refetch) unless live or the time input was edited — has no test.
    • Fix: Add a test asserting toggleColumn calls onSubmit with resolveTimeRange: false when !isLive && !isTimeInputEdited and true otherwise, extracting the !!isLive || isTimeInputEdited decision into a pure helper if the component harness is too heavy.
    • testing, correctness, adversarial, kieran-typescript, julik-frontend-races, performance, project-standards
🔵 P3 nitpicks (2)
  • packages/app/src/ChartUtils.tsx:219 — Setting eventTableSelect: undefined in convertToTimeChartConfig introduces an undocumented invariant that buildEventsSearchUrl must consume the pre-conversion config; a future refactor passing a converted config into it would silently drop the custom "View events" select with no type error or test to catch it.
    • Fix: Add a comment at the buildEventsSearchUrl call site in DBTimeChart.tsx noting it must use the unconverted config, and add a test pinning that the custom select survives conversion.
    • maintainability, testing
  • packages/app/src/components/Search/histogramWith.ts:22 — getReferencedWithClauses substring-matches alias names against a JSON.stringify haystack, so an alias name containing JSON-escaped characters could be dropped (producing a wrong query) and common-word alias names (e.g. source, where) always match structural JSON keys and are always kept, weakening the refetch-avoidance; both are low-likelihood since SQL aliases are typically alphanumeric.
    • Fix: Match against the relevant raw config field strings rather than the serialized JSON, and skip empty clause.name values.
    • correctness, adversarial, maintainability, performance, kieran-typescript

Reviewers (11): correctness, adversarial, kieran-typescript, julik-frontend-races, performance, testing, maintainability, project-standards, previous-comments, agent-native, learnings-researcher.

Testing gaps:

  • No regression test asserting the histogram query key (post-conversion with + select=count + eventTableSelect=undefined) is byte-stable across a column toggle.
  • No getReferencedWithClauses test for the substring over-inclusion case or a transitive chain deeper than two aliases.
  • No test for the "typed-but-unapplied range, then toggle column" path, where the pending range is applied as a side effect of the toggle.

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 — 39998be1 Deployed Nov 20, 2026 by vercel[bot]
Preview – hyperdx-storybook — 39998be1 Deployed Nov 20, 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