-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[HOLD for payment 2024-08-02] Moize - general purpose memoization tool #42200
Comments
Triggered auto assignment to @puneetlath ( |
New Library Review
Once these questions are answered, start a thread in #engineering-chat, ping the
|
After researching this, one of the things I like about moize is how the base API is extremely simple, but it's also configurable for just about any kind of memoization you might need. |
Can you give some examples of such scenarios and where we encounter this problem? |
Here are just a few examples of different caching solutions we've built ad-hoc:
A case study I was involved with can be found in this PR. The diff in const translateMemoized = moize(translate);
export {translateMemoized as translate}; and lots of discussion could have been avoided with this standardization. |
Other case I added recently that could use this App/src/components/ThumbnailImage.tsx Line 19 in e8ae3c5
|
@kacper-mikolajczak can you please post this in the #expensify-open-source channel in problem/solution format along with all the information provided in the OP? And cc @app-deployers on it. Thank you! |
Sure thing @puneetlath! Here is a P/S post. |
From looking at https://github.com/planttheidea/moize/releases, it looks like the last release was May 2023, last year. Correct? |
Looks like the discussion is ongoing. |
ProposalIntroGoal of the proposal is to find API for a future memoization standard. By looking at the current use-cases in the codebase, we will try to distill minimal API surface which is going to be used for the implementation. ExamplesLodash There are two instances of lodash The Line 69 in 92a7b15
Same goes for second use-case which is App/src/libs/LocaleDigitUtils.ts Line 16 in 92a7b15
Intl-like modules
This use-case requires deep comparison of arguments, because options passed to Intl methods are possibly going to be the same across the app, but have different references. Maps Many samples of using Maps were provided, like ones below:
Based on those examples we would need to employ value caching mechanism (instead of function caching) which could be achieved by overloading RequirementsHere are additional concerns and requirements that were discovered either during discussion or exploration of similar solutions (moize, memoizee etc.):
ConclusionBased on findings above and recent discussion, we can conclude that in simplest form the API could look like it: type MapCacheConfig = {
cacheMode: 'map';
// Map keys are singlular values, so we cannot compare tuple of arguments directly. We are forced to serialize arguments and then compare strings.
// It may be worth to choose if you anticipate large cache size.
equalityCheck: 'deep';
};
type ArrayCacheConfig = {
cacheMode: 'array';
equalityCheck: 'shallow' | 'deep';
};
type CacheConfig = MapCacheConfig | ArrayCacheConfig;
type MemoizeConfig = {
maxSize: number;
maxAge: number;
replacementPolicy: 'LRU';
} & CacheConfig;
type MemoizeStaticInstance<T> = {
get: (key: string) => T | undefined;
set: (key: string, value: T) => void;
clear: () => void;
}
type MemoizeInstance<Fn extends () => {}> = Fn & MemoizeStaticInstance<ReturnType<Fn>>;
type Memoize<Fn extends () => {}> = (f: Fn, config: MemoizeConfig) => MemoizeInstance<Fn>;
type Memoize<T> = (initialValue T[], config: MemoizeConfig) => MemoizeStaticInstance<T>; In the next comment I will add information about possible implementation obstacles. Let me know what you think, thanks! |
@puneetlath Whoops! This issue is 2 days overdue. Let's get this updated quick! |
@kacper-mikolajczak What is your ETA for this POC? |
@kacper-mikolajczak what's the next step here? |
@kacper-mikolajczak has a POC for a custom-build general purpose memoization tool (not moize) here. It went through some reviews but he's OOO this week so I assume it will pick back up next week |
How's it going @kacper-mikolajczak? |
@puneetlath i believe this is now waiting for @roryabraham to check the changes made after his previous review |
Hi @puneetlath, exactly as @mountiny said 🫡 |
I reviewed and approved the PR last week. Looks like @kacper-mikolajczak has an updated TODO list here |
We are getting close, I think we can merge the PR tomorrow |
|
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.12-0 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue: If no regressions arise, payment will be issued on 2024-08-02. 🎊 For reference, here are some details about the assignees on this issue:
|
Adding @mananjadhav as it looks like they were the C+ here. |
Payment Summary
BugZero Checklist (@puneetlath)
|
Payment summary:
|
$250 approved for @mananjadhav |
In order to properly evaluate if a new library can be added to
package.json
, please fill out this request form. It will be automatically assigned someone from our review team that will go through and vet the library.In order to add any new production dependency, it must be approved by the App Deployer team. They will evaluate the library and decide if it's something we want to move forward with or if other alternatives should be explored.
Note: This is only for production dependencies. While we don't want people to add packages to dev-dependencies willy-nilly, we recognize that there isn't as great of a need there to secure them.
Name of library: Moize
Details
fast-equals
andmicro-memoize
butfast-equals
is already used, not sure aboutmicro-memoize
)Issue Owner
Current Issue Owner: @puneetlathThe text was updated successfully, but these errors were encountered: