Skip to content

Backport efficient copy#2769

Merged
197g merged 7 commits intoversion-0.25from
backport-efficient-copy
Feb 13, 2026
Merged

Backport efficient copy#2769
197g merged 7 commits intoversion-0.25from
backport-efficient-copy

Conversation

@197g
Copy link
Member

@197g 197g commented Feb 13, 2026

Backport of: #2766 , #2768 to 0.25*

This has been a long standing issue. The lack of generalization in Rust
makes it generally hard to provide specialized implementations of
`copy_from` that can make full use of the layout information to improve
code generation. Since the argument is generic we stay with the default
implementation even for the very strict targets (and source) of
`ImageBuffer`.

We sidestep a large part of the problem by speeding up only the copy
from a well-described layout: `View` (a strided matrix). Then an
optional method on `GenericImageView` lets us query if the source is
equivalent to such a copy. We wont reap the benefits for user defined
trait impls but importantly the crate's own `ImageBuffer` and `SubImage`
can provide it The latter also has a generic impl for

	SubImage<D> were <D as Deref>::Target: GenericImageView

Due to this we do not use a double-dispatch approach (adding a
`copy_into_buffer`) but this which composes purely at runtime.

Also note that DynamicImage can not provide it but the goal is to
replace this, too.

Backport-Of: e7d1ea2
@197g 197g force-pushed the backport-efficient-copy branch 3 times, most recently from e1f2dc8 to e73ae3d Compare February 13, 2026 07:52
197g added 6 commits February 13, 2026 08:59
This also speeds up copies from them as well as copies from sub images
of sample views.

Backport-Of: 903d448
The pattern was caught in review, went ahead and generalized it to the
other occasion where a rectangular placement is built from an image.

Backport-Of: 2861fb8
Since conversion is fallible, using `to_*` is more appropriate.

Backport-Of: 41046d3
@197g 197g force-pushed the backport-efficient-copy branch from e73ae3d to c9cbbb4 Compare February 13, 2026 07:59
@197g 197g merged commit d9ab111 into version-0.25 Feb 13, 2026
32 checks passed
@197g 197g deleted the backport-efficient-copy branch February 13, 2026 08:28
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.

1 participant