Skip to content

[HOLD for Payment 2024-09-06] [$500] [Performance] Create Onyx connection Manager #47143

Closed

Description

@mountiny

Problem

A new connection is made to Onyx every time we subscribe to a Onyx key (by using Onyx.connect(), useOnyx() or withOnyx), even if we are subscribing to the same key e.g. a collection. When the Onyx data changes, we loop through each connection ( here and here ) and perform some heavy operations in order to prepare the data to send to all the subscribers listening to that key. This approach is inefficient as we need to build the same data countless times for every subscriber, leaving to the developer to build custom solutions in their codebase if they want to optimize and reuse the connections.

Solution

Let’s reuse the connections automatically inside Onyx with the Onyx Connection Manager. This manager will take care of identifying and reuse the connections every time we have multiple subscribers to the same Onyx key with the same connect configuration. When the data changes we’ll only need to prepare the data one time and send to all the subscribers immediately instead of doing this operation for each one, saving memory, processing and reducing the overall JS overhead.

This solution requires pratically no significant changes in E/App and will benefit both Onyx.connect() and useOnyx() subscribers. Unfortunately the withOnyx() HOC connects to Onyx in a different way than the first ones and therefore they can’t be reused in the same way, so they will function normally as it is today (one connection per subscriber).

With this solution applied to E/App, the average amount of connections will be reduced in about 30% 🚀 When the entire codebase is migrated from withOnyx() to useOnyx(), the expected reduction will be around 80-90% 🤯

Before:
Opening a report: 1749 connections
Switching between reports: 4121 connections

After:
Opening a report: 1238 connections (-30%)
Opening a report (projection after migration from withOnyx() to useOnyx()): 340 connections (-80%)
Switching between reports: 2604 connections (-36%)
Switching between reports (projection after migration from withOnyx() to useOnyx()): 399 connections (-90%)

Here’s the Onyx PR and the E/App PR!

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0142380df7c5dd6bd5
  • Upwork Job ID: 1823838590285150645
  • Last Price Increase: 2024-08-14
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @lschurr

Activity

  1. added
    Daily
    Bug
    on Aug 9, 2024
  2. self-assigned this
    on Aug 9, 2024
  3. added
    AutoAssignerNewDotQuality
    on Aug 9, 2024
  4. melvin-bot commented on Aug 9, 2024

    @melvin-bot

    Triggered auto assignment to @lschurr (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  5. melvin-bot commented on Aug 9, 2024

    @melvin-bot

    Current assignee @mountiny is eligible for the AutoAssignerNewDotQuality assigner, not assigning anyone new.

  6. fabioh8010 commented on Aug 9, 2024

    @fabioh8010
    Contributor

    Hi, I'm Fábio - expert agency contributor - and I would like to work on this issue!

  7. codewaseem commented on Aug 9, 2024

    @codewaseem
    Contributor

    Also, I noticed sometimes the withOnyx() causes infinite re-renders. #47041 (comment)

  8. melvin-bot commented on Aug 12, 2024

    @melvin-bot

    @fabioh8010, @lschurr, @mountiny Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  9. lschurr commented on Aug 12, 2024

    @lschurr
    Contributor

    Is there an update on this issue @fabioh8010?

  10. 18 remaining items

  11. ikevin127 commented on Aug 21, 2024

    @ikevin127
    Contributor

    Dropped my test results so far all 🟢 Passing, see #44987 (comment) for details.
    Moving forward I think the next thing to do is have an ad-hoc build of the E/App PR and have the QA team's results to go off and triage all found issues (if any) before moving forward with merging.

  12. added
    Reviewing
    Weekly
    and removed
    Daily
    on Aug 23, 2024
  13. mountiny commented on Aug 27, 2024

    @mountiny
    ContributorAuthor

    We have merged and deployed this PR to staging. Investigating if the was any performance regression from this PR noticed

  14. ikevin127 commented on Aug 30, 2024

    @ikevin127
    Contributor

    ⚠️ We just got confirmation on Slack that the Deploy Checklist: New Expensify 2024-08-26 which includes the PR of this issue was only deployed to production today in Deploy Checklist: New Expensify 2024-08-28. More context on why this happened can be found in this Slack thread and this Slack comment.

    Given the context above, this issue should be on [HOLD for Payment 2024-09-6] according to today’s production deploy from Deploy Checklist: New Expensify 2024-08-28.

    cc @lschurr @mountiny

  15. changed the title [-][$500] [Performance] Create Onyx connection Manager[/-] [+][HOLD for Payment 2024-09-06] [$500] [Performance] Create Onyx connection Manager[/+] on Sep 2, 2024
  16. added
    Awaiting Payment
    and removed
    Reviewing
    on Sep 2, 2024
  17. mountiny commented on Sep 2, 2024

    @mountiny
    ContributorAuthor

    Updated

    $500 to @ikevin127

  18. lschurr commented on Sep 6, 2024

    @lschurr
    Contributor

    Payment summary:

  19. ikevin127 commented on Sep 6, 2024

    @ikevin127
    Contributor

    @lschurr Offer accepted, thank you!

  20. lschurr commented on Sep 6, 2024

    @lschurr
    Contributor

    All set!

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

Metadata

Metadata

Labels

AutoAssignerNewDotQualityAwaiting PaymentBugExternalWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions