Skip to content

Avoid initializing generic vector clones - #572

Draft
mikamikasuki wants to merge 1 commit into
haskell:masterfrom
mikamikasuki:fix/avoid-zeroing-generic-clones
Draft

mikamikasuki wants to merge 1 commit into
haskell:masterfrom
mikamikasuki:fix/avoid-zeroing-generic-clones

Conversation

@mikamikasuki

Copy link
Copy Markdown

Generic.clone allocates its destination with M.new, which initializes the storage before unsafeCopy overwrites every element. Use M.unsafeNew, matching the mutable clone path, to avoid that redundant pass. The copy fills the destination before it is returned.

Fixes #571.

The issue's reproducer reports the cost across Storable and Unboxed vectors and GHC 9.6 through 9.14; it also reports the one-line change passing 2,808 vector-tests-O2 tests and 14 vector-inspection tests on GHC 9.10.3. I confirmed the source paths and copy invariant. This environment has no GHC/Cabal, so I have not run the Haskell tests locally; project CI is needed for validation.

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.

Generic clone fills its new vector with zeros before it copies into it, so force, modify and (//) write each element two times

1 participant