[No QA] Add PERF-17 coding-standards rule: Avoid intermediate lookup layers#94220
Conversation
|
@codex pls review |
|
@TMisiukiewicz curious what you think and whether I grasped the problem space good enough. Also if you happen to have more concrete real examples then shoot them at me ❤️ |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f42e940ee9
ℹ️ 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".
TMisiukiewicz
left a comment
There was a problem hiding this comment.
Some concerns from my side:
- The rule points at the wrong villain. #94146's whole win came from replacing the precomputed
archivedReportsIDSetdigest with the rawreportNameValuePairscollection and doing O(1) lookups insidefindLastAccessedReport. Passing the collection was the fix. The actual lesson is: don't eagerly build an expensive data structure from data you already hold to satisfy a conditional/per-element check; pass the raw source and index it on demand. That's a different principle than "don't pass collections to lazy callees." - The "correct" fix recommends a deprecated, staleness-prone path. It relies on the module-scoped
Onyx.connectWithoutViewfallback inside the util which is the pattern we've been removing for months because those values can be stale or not-yet-hydrated
If you need any help in reframing this rule, let me know 😊
|
Thanks @TMisiukiewicz, this are exactly the remarks I was looking for ❤️ Let me know what you think of the rule now and if you have more examples, I am more than happy to add those. Thanks! |
TMisiukiewicz
left a comment
There was a problem hiding this comment.
Looks good 👍 leaving two more concerns
|
|
||
| **DO NOT flag if:** | ||
|
|
||
| - The digest is reused across many lookups in a hot path and is built once (memoized/stable, not rebuilt every render) - a genuine precompute win. |
There was a problem hiding this comment.
I think AI might have problems to decide whether a memoized part is a precompute win since from the diff it's difficult to reason about the call frequency. Any ideas how we could improve this? 🤔
There was a problem hiding this comment.
Right call. Improved the instructions to search via Grep outside a diff for marks of this, too.
|
|
||
| ### Reasoning | ||
|
|
||
| Building a derived lookup structure (`new Set`/`new Map`/`Object.fromEntries` or a hand-built index) from a collection you already hold - just to answer membership/per-element checks downstream - is O(n) construction, often re-run every render, for something the callee can index O(1) straight from the raw source. Pass the raw collection and do the lookup on demand inside the callee instead. In [#94146], replacing a precomputed archived-IDs `Set` with the raw `reportNameValuePairs` collection plus O(1) lookups inside `findLastAccessedReport` cut ~14s on a 100k-report account. This is extra wasteful when the callee runs conditionally/lazily, since the digest is built even when it's never used. |
There was a problem hiding this comment.
This is extra wasteful when the callee runs conditionally/lazily, since the digest is built even when it's never used
this might be actually translated into a Flag when... condition, wdyt?
- Replace the memoization carve-out with a diff-observable test (repeated/visible lookups), defaulting to flag when usage isn't visible. - Promote the conditional/lazy-callee note into an explicit higher-confidence flag signal. - Add lazy-callee search-pattern hints.
|
How is this looking? |
Clarify when to flag eager lookup construction, tighten confidence criteria, and reduce over-triggering patterns so review signals are more actionable. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hi folks! Sorry for the pause here - got involved with higher prio items. All the review comments are now addressed. Also, refined a bit flags, title and added better examples (in my opinion). @TMisiukiewicz happy to get your final review on this one. Thanks! |
|
@ikevin127 @mountiny One of you needs to 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] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4148256fb
ℹ️ 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".
|
@mountiny I'm assuming this doesn't need C+ review, let me know otherwise! |
|
Thanks @TMisiukiewicz, adjusted to |
|
Also needed to fix commits signing but the PR should be ready now :) |
Addresses codex P2: Set/Map built from an array to avoid O(n) .includes is a real O(1) win, not a violation. Restrict rule to already-keyed raw sources and drop the .includes search pattern.
a377431 to
f2a2079
Compare
|
Hey 👋 Wanted to let you know that I'll be out of office tomorrow. The PR should be ready for merge - if anything happens otherwise, I will resolve when I am back 🫡 |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.33-0 🚀
|
|
🚀 Deployed to production by https://github.com/lakchote in version: 9.4.33-8 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Adds coding-standards reviewer rule PERF-17 (
.claude/skills/coding-standards/rules/perf-17-avoid-intermediate-lookup.md) and indexes it inSKILL.md. The rule flags eager construction of intermediate lookup layers from already-keyed data and recommends passing raw sources with on-demand lookup. Docs-only; no runtime code changes.Fixed Issues
$ #94219
PROPOSAL:
Tests
SKILL.md.Offline tests
N/A
QA Steps
N/A - docs-only change.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari