gqty icon indicating copy to clipboard operation
gqty copied to clipboard

Disable variables serialization cache

Open sergeysova opened this issue 3 years ago • 5 comments

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?

sergeysova avatar Mar 06 '22 09:03 sergeysova

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

vicary avatar Mar 06 '22 10:03 vicary

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

sergeysova avatar Mar 06 '22 12:03 sergeysova

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

PabloSzx avatar Mar 06 '22 13:03 PabloSzx

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 https://github.com/gqty-dev/gqty/blob/cbb3e583acc77d7e87c874559c8c674ca6effec5/packages/gqty/src/Selection/SelectionManager.ts#L122-L132.

vkrol avatar Mar 15 '22 16:03 vkrol

After further investigation, I came to the conclusion that the problem is not in WeakMap, but in stringsHash in the module SelectionManager.ts https://github.com/gqty-dev/gqty/blob/cbb3e583acc77d7e87c874559c8c674ca6effec5/packages/gqty/src/Selection/SelectionManager.ts#L122-L132.

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 😢

PabloSzx avatar Mar 15 '22 17:03 PabloSzx