-
Notifications
You must be signed in to change notification settings - Fork 25
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
Take loader_factory instead of loader in JsonldOptions
#143
Comments
You are absolutely right, wrapping loaders (which have an async API) into a (sync) Mutex is an aberration. My bad! However, I'm not entirely convinced by your assertion that loaders are "usually cheap to clone or construct". Some loaders may maintain an in-memory copy of frequently used (and possibly big) contexts. Similarly, HTTP loaders should rely on some form of caching (which could be on disk or in memory). Copying those in-memory caches would be inefficient. The alternative would be to resort to some kind of mutex inside the loaders... So I would keep the idea of wrapping the loader in a mutex, but use futures-util's async Could you maybe make a PR with these changes? |
The rust pattern for this is to use interior mutability, wrapped in an
And for on disk cache, like
|
That still makes the parser "effective" non concurrent, as each parser usage effectively have to wait for others to complete. It would be really practical to use a loader factory. If it is considered okay, i should make a pr with that. |
The sync mutex is perfectly fine, as lock is acquired in non-async context. It will not block runtime. Issue was not about parsing task blocking the runtime, but about inability to run multiple parsing tasks concurrently using the same parser, as all tasks have to wait for the lock on config mutex. May be, that's fine enough, as we can instantiate new parser for each task. Mentioning in docs will be greatly helpful though. |
Indeed. I stand corrected. Same for caches being cheap to clone.
I see that now.
Since this would be specific to the JSON-LD parser, while all other parsers are "concurrency friendly", this is probably not the best option. I'm reopening this issue, and I'm welcoming a PR replacing "loader" with a "loader_factory" :) |
This was actually included in v0.8.0 |
Current
JsonLdOptions<L>
takes a loader of typeL
, and wraps it in aMutex
. It effectively makes jsonld parser non concurrent, as every concurrent op have to wait anyway till others complete.Instead, it will be great to take a loader-factory
fn() => L
, that can return fresh loader on every call. As most loaders can be cheap to clone or construct, it will enable concurrency without much cost.The text was updated successfully, but these errors were encountered: