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 Building Building Preview Nov 24, 2026 11:27pm UTC
hyperdx-storybook Building Building Preview Nov 24, 2026 11:27pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a357775

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

This PR includes changesets to release 4 packages
Name Type
@hyperdx/app Patch
@hyperdx/common-utils 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

github-actions Bot commented Nov 20, 2026 •

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 107 in total (1.12%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

Comment thread packages/app/src/DBSearchPage.tsx Resolved
@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/DBSearchPage.tsx:2020 — The new time-range and alias-filtering behaviour on the search page has no tests → The new tests only cover getReferencedWithClauses on its own, plus one check that convertToTimeChartConfig sets eventTableSelect to undefined. Nothing tests three things: that toggleColumn skips onSearch when the time input is unedited and not live; that it still re-resolves the range when the input was edited or live tail is on; and that the histogram haystack (JSON.stringify of chartConfig plus groupBy) keeps an alias used only in filters, implicitColumnExpression or the sample-weight expression. Add a DBSearchPage or hook-level test for each path so a regression in isTimeInputEdited or in the haystack fields gets caught.

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 • 1188s

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

Scope: 3 production files (packages/app/src/ChartUtils.tsx, packages/app/src/DBSearchPage.tsx, packages/common-utils/src/core/utils.ts) + 2 test files + 1 changeset, diffed against 514db543.
Intent: Stop the search-page histogram from refetching on column add/remove and alias add by stabilizing its React Query key — drop eventTableSelect from the converted config, include only referenced WITH clauses, and skip relative-time re-resolution on column toggles.

Both deep reviewers traced the three failure vectors (View Events links, WITH-clause under-inclusion, time-input state machine) against the real code and confirmed no break on today's code paths: View Events reads eventTableSelect from the unconverted config, the histogram query serializes every alias-referencing field into the match haystack, and the two time-input states diverge only on genuine user edits.

✅ No critical issues found. Recommended items below.

🟡 P2 -- recommended

  • packages/app/src/DBSearchPage.tsx:2016 -- The PR's core behavior — the column-toggle gate (resolveTimeRange: !!isLive || isTimeInputEdited) and the select/orderBy-blanking that drops table-only aliases from the histogram WITH set — is exercised only at the leaf utils, so inverting the gate or changing the alias filter would silently reintroduce the refetch (or break time updates) with no failing test.
    • Fix: Add a DBSearchPage test (or extract the gate into a pure helper) asserting an unedited non-live toggle does not call onSearch, an edited-or-live toggle does, and an alias referenced only in the table select is excluded while a where/groupBy alias is kept.
    • testing, frontend-races, adversarial, correctness
🔵 P3 nitpicks (5)
  • packages/common-utils/src/core/utils.ts:1735 -- getReferencedWithClauses can under-include a needed clause when a clause name is JSON-escaped in the stringified haystack, or when a kept clause is subquery-based with sql undefined and so contributes nothing to the transitive haystack; no live path today because aliases are plain identifiers referenced textually, but the invariant is undefended in an exported util.
    • Fix: Match against the raw field values rather than JSON.stringify output and serialize clause.chartConfig into the haystack, or narrow the parameter type to sql-based clauses.
    • correctness, kieran-typescript
  • packages/common-utils/src/core/utils.ts:1726 -- Raw substring matching keeps an alias like Service whenever a longer token such as ServiceName appears, so toggling that column still changes the referenced set and refetches; over-inclusion never breaks a query but partially defeats the optimization.
    • Fix: Use word-boundary matching if tighter refetch suppression is required, and add a regression case pinning the intended behavior.
    • adversarial, testing
  • packages/common-utils/src/core/utils.ts:1718 -- The texts parameter name and JSDoc describe behavior but not the caller contract (pass every alias-referencing string; omit the columns you want ignored).
    • Fix: Rename to referencingTexts and document the caller obligation in the JSDoc.
  • packages/app/src/DBSearchPage.tsx:1312 -- The two-setter convention (raw setDisplayedTimeInputValue for typing only, applied changes through setAppliedTimeInput) is unenforced, so a future miswire would silently break isTimeInputEdited and reintroduce the refetch.
    • Fix: Add a pointer comment at the raw useState declaration or narrow the raw setter's exposure to the input component.
  • packages/app/src/DBSearchPage.tsx:2020 -- On a column toggle with a typed-but-unsubmitted time value, the gate resolves displayedTimeInputValue and applies a range the user never searched; this matches the prior unconditional onSearch and is pre-existing, not introduced here.
    • Fix: If undesired, gate the toggle path on an explicit submit flag rather than reusing the edited sentinel.
    • adversarial

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

Testing gaps:

  • No test asserts getReferencedWithClauses drops a select/orderBy-only alias while keeping a where/groupBy/timestamp alias on the real histogram config shape.
  • No test covers transitive retention (clause A in where, A.sql referencing clause B, asserting B survives the while(added) rescan).
  • No test verifies the View Events link still carries eventTableSelect after convertToTimeChartConfig blanks it on the queried config.

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

@knudtty
knudtty force-pushed the aaron/prevent-unnecessary-histogram-rerender branch from 69f52c0 to b2c7378 Compare November 24, 2026 22:36
// Preserve the original table select string for "View Events" links
// Everything but the table's select and sort can reference an alias,
// including the body, timestamp and sample-weight expressions.
with: getReferencedWithClauses(aliasWith, [

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 — Histogram still refetches, and briefly loses its alias, on a column toggle when the WHERE uses a table alias

aliasWith comes from useAliasMapFromChartConfig(dbSqlRowTableConfig) (packages/app/src/hooks/useChartConfig.tsx:571). That query is keyed on select and sets no placeholderData, so after a column toggle aliasMap is undefined until the new query finishes. If the search references an alias (e.g. service:api with ServiceName as service), the histogram's with goes from the clause to undefined and back. That runs one query with an unknown identifier and then a second one, which is the refetch this PR is meant to prevent. Fix: keep the previous alias map while the new one loads (placeholderData: keepPreviousData), or memoize the filtered with on the clause contents, not on the aliasWith reference.

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

@knudtty
knudtty force-pushed the aaron/prevent-unnecessary-histogram-rerender branch from 6d64ef5 to a357775 Compare November 24, 2026 23:26

This branch was successfully deployed

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants