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

Make parallelization customizable (for wasm) #148

Open
fursund opened this issue Jan 10, 2022 · 9 comments
Open

Make parallelization customizable (for wasm) #148

fursund opened this issue Jan 10, 2022 · 9 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@fursund
Copy link

fursund commented Jan 10, 2022

Hi!

Trying to load an exr in WASM. It could look like it fails due to threadpool being used in the exr lib?

Perhaps I am just missing some setting in the toml?

Thanks!

@fursund fursund added the question Further information is requested label Jan 10, 2022
@johannesvollmer
Copy link
Owner

johannesvollmer commented Jan 11, 2022

The library is not yet tested on wasm, but it is a goal. Apart from switching parallelism off, what else is required for wasm? Maybe switching off functions with file paths?

Using concurrency is already optional in the library, we would only have to disable the rayon dependency and some type definitions, in order to use single-threaded exr on wasm

@johannesvollmer johannesvollmer added the enhancement New feature or request label Jan 11, 2022
@fursund
Copy link
Author

fursund commented Jan 11, 2022

File IO I've already worked around with the buffered loading, which I think is fine for now. How would I switch of concurrency?

@fursund
Copy link
Author

fursund commented Jan 11, 2022

Perhaps using this could work: https://github.com/GoogleChromeLabs/wasm-bindgen-rayon

@fursund
Copy link
Author

fursund commented Jan 11, 2022

I see I could get it to work using "non_parallel()".... but it takes forever to load the EXR compared to the same code running natively.

@johannesvollmer
Copy link
Owner

johannesvollmer commented Jan 11, 2022

File IO I've already worked around with the buffered loading

Excellent! So it's simply enough to not use the path-based functions? I thought it would be necessary to remove the functions when compiling for wasm. Nice!

I see I could get it to work using "non_parallel()".... but it takes forever to load the EXR compared to the same code running natively.

The library uses rayon only for testing purposes, the runtime code uses threadpool and flume.
Unless these work on wasm, performance will be the trade-off, unfortunately. Alternatively, we could try to make the whole parallelization/threadpool functionality customizable.

@johannesvollmer
Copy link
Owner

johannesvollmer commented Jan 12, 2022

Here's an article about threading in wasm:
https://rustwasm.github.io/wasm-bindgen/examples/raytrace.html

Seems like it will not be simple. Even if the parallelization mechanics in exrs were customizable, it would be quite the hassle to make threads work at all

@fursund
Copy link
Author

fursund commented Jan 12, 2022

Not sure why, but it seems like my wasm was somehow broken. I managed to rebuild it again, and now it's almost as fast as the native binary. So actually not having threading at load is not a problem after all. Thanks your help!

@johannesvollmer
Copy link
Owner

johannesvollmer commented Jan 12, 2022

Awesome!

The loading time depends on whether the file uses exr compression, and of course the image size. Uncompressed images should be unaffected by parallelism. RLE compression is fastest, PIZ is reasonably fast, and the other compression types use the zip algorithm, which takes quite some time

@johannesvollmer
Copy link
Owner

Leaving this issue open as a reminder to add parallelization customization :)

@johannesvollmer johannesvollmer changed the title Loading EXRs in WASM? Make parallelization customizable (for wasm) Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants