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

Improve caching behavior #55

Open
tuner opened this issue May 24, 2023 · 2 comments
Open

Improve caching behavior #55

tuner opened this issue May 24, 2023 · 2 comments

Comments

@tuner
Copy link
Contributor

tuner commented May 24, 2023

Hi,

I'm loading BigWig data for the whole genome, i.e., calling getFeatures for each chromosome. This results in many fetch requests, as expected.

GC

However, the number of requests seems to be excessive (76), and many of them hit exactly the same range. For example, in the above case (https://genomespy.app/docs/grammar/data/lazy/#example_1), there are 25 requests hitting the same 49 byte range and other 25 requests hitting a same 8197 range. Because web browsers seem to be very bad at caching partial content, this results in quite a bit of latency.

There appears to be a caching mechanism in BlockView, but a new BlockView (and cache) is created for each getFeatures call.

private featureCache = new AbortablePromiseCache<ReadData, Buffer>({

Instead of having a new cache for each BlockView, could there be a single shared cache in the BBI class, which could be used by all BlockViews? In my example case, the number of requests would drop from 76 to 28.

I could make a PR at some point if this change is feasible and would not cause any undesired adverse effects.

@cmdcolin
Copy link
Collaborator

cmdcolin commented May 24, 2023

I would definitely be open to improvements here. We use https://github.com/rbuels/http-range-fetcher which smooths over some issues like this (it is a special fetch implementation that tries to combine multiple fetch requests and cache results, it was especially useful for cram-js iirc) but would be interested in making the default experience better too

@tuner
Copy link
Contributor Author

tuner commented May 24, 2023

Ok! I'll do some experiments and make a PR if my proposal appears to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants