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

Disable variables serialization cache #700

Open
sergeysova opened this issue Mar 6, 2022 · 5 comments
Open

Disable variables serialization cache #700

sergeysova opened this issue Mar 6, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@sergeysova
Copy link

We're trying to upload file thru useMutation and pass File to mutation argument.

But because of variable serialization via WeakMap GC cannot clear cache.

image

How can we disable this cache for variables serialization?

@vicary
Copy link
Member

vicary commented Mar 6, 2022

WeakMap is by definition allow garbage collection and is prune to lost anytime, what exactly is the problem you are observing?

@sergeysova
Copy link
Author

We have crash of the browser on the devices with small amount of memory

@PabloSzx
Copy link
Member

PabloSzx commented Mar 6, 2022

It should be possible to have a core client configuration to globally disable serialization cache, but doing it per query/mutation is impossible.

But at the same time, the cache should be garbage collected with WeakMap, this is might be unexpected behavior from the js engine.

On the other hand, the serialization is being weakly cached because the client logic requires very frequent serialization of variables and data, and disabling it might mean slower performance, but I can see the requirement of gqty being run in devices with very low memory where having the serialized version of "every" object is already too much extra memory usage

@vkrol
Copy link

vkrol commented Mar 15, 2022

But at the same time, the cache should be garbage collected with WeakMap, this is might be unexpected behavior from the js engine.

After further investigation, I came to the conclusion that the problem is not in WeakMap, but in stringsHash in the module SelectionManager.ts

const stringsHash: Record<string, number> = {};
let restoredBackup: SelectionsBackup | undefined;
function getSerializedVariablesId(variables: Record<string, unknown>) {
const serializedVariables = serializeVariables(variables);
let hashId: number;
if ((hashId = stringsHash[serializedVariables]) === undefined) {
hashId = stringsHash[serializedVariables] = ++incHashId;
.

@PabloSzx
Copy link
Member

After further investigation, I came to the conclusion that the problem is not in WeakMap, but in stringsHash in the module SelectionManager.ts

const stringsHash: Record<string, number> = {};
let restoredBackup: SelectionsBackup | undefined;
function getSerializedVariablesId(variables: Record<string, unknown>) {
const serializedVariables = serializeVariables(variables);
let hashId: number;
if ((hashId = stringsHash[serializedVariables]) === undefined) {
hashId = stringsHash[serializedVariables] = ++incHashId;
.

Interesting, thank you for taking the time for it, the issue here is that gqty needs to keep track of the serialized version of the variables to be able to know what unique alias corresponds to a specific query, one alternative would be to hash the variables into a short version, but that would be a lot slower 😢

@vicary vicary added the enhancement New feature or request label Dec 4, 2022
@vicary vicary mentioned this issue Dec 4, 2022
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants