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

[Performance] Return variable if no keys are changed #37822

Closed
muttmuure opened this issue Mar 6, 2024 · 2 comments
Closed

[Performance] Return variable if no keys are changed #37822

muttmuure opened this issue Mar 6, 2024 · 2 comments
Assignees
Labels

Comments

@muttmuure
Copy link
Contributor

Problem

In OnyxCache.js we have getAllKeys method, which upon invocation generates a new Array from the set and returns it. Below is how it looks as of yet:

getAllKeys() {
  return Array.from(this.storageKeys);
}

In App Startup cycle, as a result of Onyx.Connect calls we execute this method each time. We roughly have more than 30 connections which happens in App Startup cycle. As a result, each time a new array is created from the set.

Solution

We can improve this by checking whether the keys have changed and if they have changed, we create a new array and store it to a variable. And then the next time getAllKeys is invoked we will just return this variable if no keys are changed.
Let’s see how it looks like in action:

// In OnyxCache.js
constructor() {
	...
 this.keysArray = [];
 this.hasChanged = false;
	...
}

getAllKeys() {
  if (this.hasChanged) {
    this.keysArray = Array.from(this.storageKeys);
  }
  this.hasChanged = false;
  return this.keysArray;
}

addKey(key) {
	 ……
  this.hasChanged =  true;
}

merge(data){
   .....
   this.storageKeys = new Set([...storageKeys, ...mergedKeys]);

// set the flag to indicate that the keys have changed
   this.hasChanged = true;
   .....
}


drop(key) {
		……
  this.hasChanged =  true;
}

From @hurali97

@muttmuure muttmuure moved this to CRITICAL in [#whatsnext] #quality Mar 6, 2024
@muttmuure muttmuure moved this from CRITICAL to HIGH in [#whatsnext] #quality Mar 6, 2024
@muttmuure muttmuure added the Weekly KSv2 label Mar 6, 2024
@hurali97
Copy link
Contributor

hurali97 commented Mar 7, 2024

Hey @muttmuure, please assign this to me 👍

Copy link

melvin-bot bot commented Apr 5, 2024

This issue has not been updated in over 15 days. @hurali97 eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@muttmuure muttmuure moved this from HIGH to Done in [#whatsnext] #quality May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

2 participants