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

Remove some allocations from HDR Decoder #1965

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JulianKnodt
Copy link
Contributor

A larger change was proposed in #1599,
but this is intended to fix #1882 precisely.

It adds extra trait implementations to Pixels, and removes the allocation while keeping the API the same.

@fintelia
Copy link
Contributor

I've only skimmed it, but this PR looks kinda hard to review because moves around a bunch of finicky code.

One thing that particularly stands out to me though is that it uses a macro to generate generic, unsafe trait impls, on a public type. That's both a public API addition and inserts new unsafe code to the library. Potentially hard to justify for a minor perf improvement

@JulianKnodt
Copy link
Contributor Author

JulianKnodt commented Jul 19, 2023

One alternative is to create a clone of the image_transform which instead returns the colors in place.

Other than exposing an unsafe impl directly to the users, it's also possible to directly transmute the underlying types at the point where the bytemuck cast was added. I wasn't sure if that would be more or less preferred.

@fintelia
Copy link
Contributor

Looking though this now, the PR basically just changes a memcpy into an unsafe transmute? That's not an improvement IMO. We'd ideally like this crate to be #[forbid(unsafe_code)], and while we're not quite there yet, I'd really rather not add any more unsafe in the meantime

@JulianKnodt
Copy link
Contributor Author

JulianKnodt commented Jul 19, 2023

For me, as long as the unsafe code is entirely within the confines of the API and with controlled types, then it's fine to introduce. But that's a personal opinion, so I've ripped it out & should be cleaner now.

@JulianKnodt JulianKnodt force-pushed the hdr_decoder branch 3 times, most recently from 7f9b197 to 94847fa Compare July 19, 2023 16:16
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

Successfully merging this pull request may close these issues.

Unnecessary memset()+memcpy() in HDR decoding
2 participants