Skip to content

Perf: Add diagnostic sub-spans to ManualOpenSearchRouter#83076

Open
mountiny wants to merge 12 commits intomainfrom
vit-searchRouter-diagnosticSubSpans
Open

Perf: Add diagnostic sub-spans to ManualOpenSearchRouter#83076
mountiny wants to merge 12 commits intomainfrom
vit-searchRouter-diagnosticSubSpans

Conversation

@mountiny
Copy link
Contributor

@mountiny mountiny commented Feb 20, 2026

Explanation of Change

The ManualOpenSearchRouter Sentry span currently has no child spans — Sentry shows 100% self-time with no breakdown, making it impossible to identify which phase is the bottleneck. This PR adds 4 diagnostic child spans (linked via parentSpan) that decompose the parent span into sequential, non-overlapping phases:

  1. SearchRouter.ModalCloseWait — Time waiting for Modal.close() callback. Identifies if the modal system adds latency before we even start mounting the search UI.
  2. SearchRouter.OptionsInit (cold path only) — Time spent in createOptionList(). Only fires when the parent span is active (guarded by getSpan() check to avoid noise from other useOptionsList consumers).
  3. SearchRouter.ComputeOptions — Total JS computation time in SearchAutocompleteList (searchOptions, autocompleteSuggestions, sections assembly). Only measured on first render.
  4. SearchRouter.ListRender — FlashList rendering + native layout time (from post-computation to onLayout). Only measured on first render.

All sub-spans pass parentSpan: getSpan(CONST.TELEMETRY.SPAN_OPEN_SEARCH_ROUTER) so they appear as children of the parent ManualOpenSearchRouter span in Sentry's trace view. If the component unmounts before spans complete (e.g., the user closes the search router quickly), a cleanup useEffect calls cancelSpan() to prevent leaks — these get a canceled attribute to distinguish them from normal completions.

The gap between sub-spans (parent minus all children) gives us the React mount + Onyx hydration overhead without requiring a dedicated span.

Additionally, 2 attributes are added to the parent span for Sentry segmentation:

  • cold_start: true/false — whether options needed initialization when SearchRouter mounted (set via useEffect to read the correctly synced context value)
  • trigger: 'button'/'keyboard' — how the search was opened (button path was previously missing this)

Overhead is negligible (~8 Date.now() calls per open). Sub-spans only fire on the initial render, guarded by refs.

Fixed Issues

$ #79353

Tests

  1. Open the app and navigate to any screen with the search button
  2. Click the search button (or press Cmd+K / Ctrl+K)
  3. Verify the search router opens normally with autocomplete suggestions
  4. Close the search and open it again
  5. Verify the search router opens normally on subsequent opens
  6. Check the JS console — no errors related to spans or telemetry
  • Verify that no errors appear in the JS console

Offline tests

  1. Turn off network connection
  2. Open the search router via button or Cmd+K
  3. Verify it opens normally (sub-spans are fire-and-forget, no network dependency)
  4. Verify no errors in console

QA Steps

  1. Open the app on staging
  2. Open search router via the search button
  3. Verify it opens and shows autocomplete suggestions normally
  4. Open search router via Cmd+K (or Ctrl+K on Windows)
  5. Verify it opens normally
  6. Check Sentry for ManualOpenSearchRouter spans — verify child spans (SearchRouter.ModalCloseWait, SearchRouter.ComputeOptions, SearchRouter.ListRender) appear nested under the parent span
  7. Verify cold_start and trigger attributes are present on the parent span
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@mountiny mountiny requested review from a team as code owners February 20, 2026 15:47
@melvin-bot melvin-bot bot requested review from aimane-chnaif and joekaufmanexpensify and removed request for a team and joekaufmanexpensify February 20, 2026 15:48
@melvin-bot
Copy link

melvin-bot bot commented Feb 20, 2026

@aimane-chnaif Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot removed the request for review from a team February 20, 2026 15:48
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/CONST/index.ts 94.30% <ø> (ø)
...rc/components/Search/SearchRouter/SearchButton.tsx 100.00% <ø> (ø)
...onents/Search/SearchRouter/SearchRouterContext.tsx 55.17% <ø> (ø)
src/components/OptionListContextProvider.tsx 85.41% <60.00%> (-0.92%) ⬇️
src/components/Search/SearchAutocompleteList.tsx 51.51% <58.33%> (+0.23%) ⬆️
... and 7 files with indirect coverage changes

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8be55219db

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +79 to +80
parentSpan.setAttribute('cold_start', !areOptionsInitialized);
coldStartAttributeSet.current = true;

Choose a reason for hiding this comment

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

P2 Badge Set cold_start after options state has synchronized

This sets cold_start during the first render and then permanently locks it via coldStartAttributeSet, but useOptionsList() initializes areOptionsInitialized to false and only syncs it from context in an effect (OptionListContextProvider.tsx uses useState(false) then updates in useEffect). On warm opens, this render still sees false, so the ManualOpenSearchRouter span is incorrectly tagged cold_start=true and never corrected, which breaks warm vs cold segmentation.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid concern — addressed in ff0acd5. The cold_start attribute was being set during render, before useOptionsList() had synced areOptionsInitialized from context (internal useState(false) always returns false on first render). Moved the attribute setting into a useEffect with [areOptionsInitialized] dependency so it reads the correctly synced value. Warm opens now correctly get cold_start=false.

Add 4 sub-spans and 2 attributes to the ManualOpenSearchRouter Sentry span
to identify which phases of the search router opening are bottlenecks.

Sub-spans:
- SearchRouter.ModalCloseWait: Modal.close() callback latency
- SearchRouter.OptionsInit: Cold-path createOptionList() cost (guarded)
- SearchRouter.ComputeOptions: JS computation in SearchAutocompleteList (guarded)
- SearchRouter.ListRender: FlashList rendering + native layout

Attributes:
- cold_start: whether options needed initialization
- trigger: 'button' or 'keyboard'

Co-authored-by: Cursor <cursoragent@cursor.com>
@mountiny mountiny force-pushed the vit-searchRouter-diagnosticSubSpans branch from 8be5521 to 9a89d49 Compare February 23, 2026 16:08
Move cold_start attribute setting to useEffect so it reads the synced
areOptionsInitialized value instead of the initial useState(false).

Add cleanup effect in SearchAutocompleteList to cancel ComputeOptions
and ListRender spans if the component unmounts before they complete.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Contributor

🚧 @mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@mountiny
Copy link
Contributor Author

@aimane-chnaif @JakubKorytko @staszekscp This is ready for a review if you could check it out please and @aimane-chnaif if you can test out the spans work as you would expect in sentry too, thanks!

@aimane-chnaif
Copy link
Contributor

aimane-chnaif commented Feb 26, 2026

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-02-28.at.12.17.33.pm.mov

@aimane-chnaif
Copy link
Contributor

Conflicts

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff0acd5c85

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +913 to +916
if (isInitialRender && computeSpanStarted.current) {
endSpan(CONST.TELEMETRY.SPAN_SEARCH_ROUTER_COMPUTE_OPTIONS);
startSpan(CONST.TELEMETRY.SPAN_SEARCH_ROUTER_LIST_RENDER, {
name: CONST.TELEMETRY.SPAN_SEARCH_ROUTER_LIST_RENDER,

Choose a reason for hiding this comment

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

P2 Badge Run compute/list span handoff only once

isInitialRender remains true until onLayout runs, so this block executes on every re-render before first layout. Since this component subscribes to many Onyx values, those pre-layout re-renders are common; each pass calls endSpan and then starts SearchRouter.ListRender again, which truncates SearchRouter.ComputeOptions and resets list-render timing, underreporting the real first-open cost in Sentry. Guard this handoff with a one-time ref so it runs exactly once per mount.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid concern — addressed in 8b8ae8d. Added a spanHandoffDone ref that gates the compute→list span handoff so it executes exactly once per mount. Before this fix, every re-render between the first render and onLayout would re-call endSpan(COMPUTE_OPTIONS) and startSpan(LIST_RENDER), resetting the list-render timing.

Additionally, during the merge with main, the loading logic (isRecentSearchesDataLoaded, skeleton) was moved from SearchRouter into SearchAutocompleteList. The loading check now runs before the span handoff as an early return, so the handoff only fires once we're past the loading state and ready to render the list.

The cold_start attribute was also moved from SearchRouter to SearchAutocompleteList since areOptionsInitialized is no longer available in SearchRouter after main's refactor.

Resolve conflicts after main moved loading logic (isRecentSearchesDataLoaded,
skeleton) from SearchRouter to SearchAutocompleteList.

Also:
- Move cold_start attribute setting to SearchAutocompleteList (areOptionsInitialized
  no longer available in SearchRouter after main's refactor)
- Guard compute→list span handoff with spanHandoffDone ref so it runs exactly
  once per mount (addresses Codex reviewer feedback)
- Add eslint-disable for intentional ref-during-render telemetry accesses

Made-with: Cursor
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b8ae8d84b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +170 to +174
if (!computeSpanStarted.current && getSpan(CONST.TELEMETRY.SPAN_OPEN_SEARCH_ROUTER)) {
startSpan(CONST.TELEMETRY.SPAN_SEARCH_ROUTER_COMPUTE_OPTIONS, {
name: CONST.TELEMETRY.SPAN_SEARCH_ROUTER_COMPUTE_OPTIONS,
op: 'function',
parentSpan: getSpan(CONST.TELEMETRY.SPAN_OPEN_SEARCH_ROUTER),

Choose a reason for hiding this comment

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

P2 Badge Start compute span after loading state clears

SearchRouter.ComputeOptions is started at the top of render before the isLoading early-return path, but it is only ended later in the first non-loading render via the handoff block. On cold opens (areOptionsInitialized is initially false), this makes the compute span include the wait for options initialization/Onyx hydration and overlap with SearchRouter.OptionsInit, so the span breakdown is no longer sequential and the compute timing is materially inflated.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid concern — addressed in a3d27e3. The COMPUTE_OPTIONS span now only starts when areOptionsInitialized is true, so on cold opens it waits until after OPTIONS_INIT completes. This eliminates the overlap and ensures the compute span only measures the actual getSearchOptions() computation, not the Onyx hydration wait.

Additionally fixed the cold_start attribute which was still reading from useOptionsList()'s internal useState(false) — warm opens were always tagged as cold. Now reads from OptionsListContext directly to get the correct synchronized value on first render.

1. Guard COMPUTE_OPTIONS span behind areOptionsInitialized so it only
   starts when real computation happens, avoiding overlap with
   OPTIONS_INIT on cold opens.

2. Read cold_start from OptionsListContext directly instead of the
   delayed useOptionsList() internal state, which always starts as
   false regardless of actual initialization status.

Made-with: Cursor
Add ATTRIBUTE_COLD_START and ATTRIBUTE_TRIGGER constants to match
the existing pattern for telemetry attribute names, replacing
bare string literals.

Made-with: Cursor
@mountiny
Copy link
Contributor Author

@aimane-chnaif any concerns from your side?

Copy link
Contributor

@aimane-chnaif aimane-chnaif left a comment

Choose a reason for hiding this comment

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

Looks good. Confirmed in Sentry

Untitled

@melvin-bot melvin-bot bot requested a review from arosiclair February 28, 2026 12:15
@melvin-bot
Copy link

melvin-bot bot commented Feb 28, 2026

@arosiclair Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4016f14677

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const computeSpanStarted = useRef(false);
const spanHandoffDone = useRef(false);
// eslint-disable-next-line react-hooks/refs -- intentional: telemetry span must start during render to measure computation time
if (!computeSpanStarted.current && areOptionsInitialized && getSpan(CONST.TELEMETRY.SPAN_OPEN_SEARCH_ROUTER)) {

Choose a reason for hiding this comment

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

P1 Badge Gate compute span to non-loading render pass

This starts SearchRouter.ComputeOptions as soon as options are initialized, even if recentSearchesMetadata is still loading and the component immediately returns the skeleton path. Because the span is only handed off/ended later in the non-loading render, it can include idle wait time and additional renders, which inflates the compute phase and corrupts the diagnostic breakdown this change is intended to provide (especially on cold opens).

Useful? React with 👍 / 👎.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 08ed61f. Hoisted isRecentSearchesDataLoaded above the compute span guard so ComputeOptions only starts once all loading states (both areOptionsInitialized and recentSearchesMetadata) have cleared. This prevents idle Onyx hydration time from inflating the span on cold opens and keeps the diagnostic breakdown sequential as intended.

Copy link
Contributor

@JakubKorytko JakubKorytko left a comment

Choose a reason for hiding this comment

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

2 questions, no requested changes, looking really good!

Comment on lines +1787 to +1790
SPAN_SEARCH_ROUTER_MODAL_CLOSE_WAIT: 'SearchRouter.ModalCloseWait',
SPAN_SEARCH_ROUTER_OPTIONS_INIT: 'SearchRouter.OptionsInit',
SPAN_SEARCH_ROUTER_COMPUTE_OPTIONS: 'SearchRouter.ComputeOptions',
SPAN_SEARCH_ROUTER_LIST_RENDER: 'SearchRouter.ListRender',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are dots in values here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The dots are intentional to visually distinguish these as diagnostic sub-spans from the top-level parent spans in Sentry's trace view. The existing parent spans use flat PascalCase (ManualOpenReport, ManualOpenSearchRouter, etc.) while these child spans use the SearchRouter. prefix to make it immediately clear they belong to the SearchRouter flow when browsing traces. It's a common Sentry convention for hierarchical span naming. Happy to change to flat PascalCase (e.g. SearchRouterModalCloseWait) if you feel consistency with the parent span naming is more important.

op: CONST.TELEMETRY.SPAN_OPEN_SEARCH_ROUTER,
attributes: {
trigger: 'keyboard',
[CONST.TELEMETRY.ATTRIBUTE_TRIGGER]: 'keyboard',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should keyboard value be in the CONSTs as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. The attribute keys (trigger, cold_start) are constants because they're the contract with Sentry and are referenced in multiple files. The attribute values ('keyboard', 'button') are each used exactly once and are self-documenting, so extracting them felt like over-abstracting. That said, it's a trivial change — happy to add TRIGGER_KEYBOARD and TRIGGER_BUTTON constants if you think it's worth it for consistency.

arosiclair
arosiclair previously approved these changes Mar 2, 2026
Copy link
Contributor

@arosiclair arosiclair left a comment

Choose a reason for hiding this comment

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

LGTM

Hoist isRecentSearchesDataLoaded above the compute span guard so
ComputeOptions only starts once all loading states have cleared,
preventing idle Onyx hydration time from inflating the span on
cold opens.

Made-with: Cursor
mountiny added 2 commits March 2, 2026 21:52
…nosticSubSpans

Made-with: Cursor

# Conflicts:
#	src/CONST/index.ts
OptionsListContext was renamed to OptionsListStateContext on main.
Update the import and useContext call to match.

Made-with: Cursor
@mountiny mountiny requested a review from arosiclair March 2, 2026 23:05
@mountiny
Copy link
Contributor Author

mountiny commented Mar 2, 2026

@arosiclair Ready again

arosiclair
arosiclair previously approved these changes Mar 3, 2026
@arosiclair
Copy link
Contributor

@mountiny conflicts

…nosticSubSpans

Made-with: Cursor

# Conflicts:
#	src/CONST/index.ts
@mountiny
Copy link
Contributor Author

mountiny commented Mar 3, 2026

@arosiclair Updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants