Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of performance.clearMarks #45122

Open
rubennorte opened this issue Jun 24, 2024 · 5 comments · May be fixed by #45206
Open

Improve performance of performance.clearMarks #45122

rubennorte opened this issue Jun 24, 2024 · 5 comments · May be fixed by #45206
Assignees
Labels
Help Wanted :octocat: Issues ideal for external contributors. Impact: Performance When the issue impacts the app running or build performance Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@rubennorte
Copy link
Contributor

rubennorte commented Jun 24, 2024

Description

We have a gated implementation of a new Performance API (via the global performance object) and PerformanceObserver.

In this implementation (see PerformanceEntryReporter), all performance entries are stored in fixed size circular buffers, which has several problems:

  1. All the entry types have the same buffer size. This is against the spec, as buffer sizes depend on the type of entry (see https://w3c.github.io/timing-entrytypes-registry/#registry).
  2. Performance for some operations isn't great. Specifically performance.clearMarks is currently an O(n) operation when given a specific entry name.

The second problem is especially relevant in a pattern commonly used to mark points/measures for profiling in the Performance tab without keeping the data in memory for performance observer:

performance.mark('point');
performance.clearMark('point');

performance.mark is currently O(1) but performance.clearMark is O(n) (being n the number of entries in the buffer), which makes this operation very slow.

We should refactor the implementation to:

  1. Explicitly separate the buffer array into specific entries for specific types.
  2. Replace the use of the circular buffer with a unordered_map mapping entry name to entry for marks and measures. We should keep the circular buffer for event types, and reduce its size to 150 (as per the spec).

React Native Version

0.74.2 / main

Affected Platforms

Runtime - Android, Runtime - iOS, Runtime - Web, Runtime - Desktop

Areas

Bridgeless - The New Initialization Flow, Other (please specify)

Web Convergence

@rubennorte rubennorte added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Jun 24, 2024
@github-actions github-actions bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Jun 24, 2024
@rubennorte rubennorte added Impact: Performance When the issue impacts the app running or build performance and removed Needs: Triage 🔍 Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Jun 24, 2024
@rubennorte rubennorte self-assigned this Jun 24, 2024
@rubennorte
Copy link
Contributor Author

cc @robik :)

@facebook facebook deleted a comment from github-actions bot Jun 24, 2024
@robik
Copy link
Contributor

robik commented Jun 24, 2024

@rubennorte Should the refactor keep the API compatibility?

@rubennorte
Copy link
Contributor Author

@rubennorte Should the refactor keep the API compatibility?

Yes, that's would be preferred for now.

I think we could use a better API but for the sake of keeping the changes scoped we should address this first.

@cortinico cortinico added Good first issue Interested in collaborating? Take a stab at fixing one of these issues. Help Wanted :octocat: Issues ideal for external contributors. and removed Good first issue Interested in collaborating? Take a stab at fixing one of these issues. labels Jun 24, 2024
@robik
Copy link
Contributor

robik commented Jun 27, 2024

@rubennorte I managed to refactor this, but not sure how to enable it so I can test it properly 😅 Would simply adding the turbomodule be sufficient?

@rubennorte
Copy link
Contributor Author

rubennorte commented Jun 27, 2024

@rubennorte I managed to refactor this, but not sure how to enable it so I can test it properly 😅 Would simply adding the turbomodule be sufficient?

Yeah, that should suffice. You can include it in react-native/ReactCommon/react/nativemodule/defaults/DefaultTurboModules.cpp and test the API in RN Tester (Performance API Example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted :octocat: Issues ideal for external contributors. Impact: Performance When the issue impacts the app running or build performance Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants