#166 always goes the slow path for most types

Open
#234 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

  • #235 by @feefladder — closed without merging

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
rust
Domain
performance

Research direction

Read src/array.rs around line 160 and the bytemuck try_cast_vec documentation linked in the issue, then compare the proposed slice conversion with the fallback path. Done means aligned allocations can use the fast path without violating deallocation alignment, while unaligned input still converts correctly; review #203 for the alternative copy-avoidance approach.

Written by the indexing model from the issue text.

Description

bytemuck's try_cast_vec for Vec<u8>->Vec<u16> or any different alignment will fail, regardless of whether the allocation is aligned. It is undefined behaviour in rust to deallocate with a different alignment than the allocation. So this code will always take the second path. That could be changed to

Ok(TypedArray::UInt16(
    try_cast_slice(data[..])
    .map(|s| s.to_vec())  // this copy already always happens
    .unwrap_or_else(
                    |(_, data)| {
                        // Fallback to manual conversion when not aligned
                        data.chunks_exact(2)
                            .map(|b| u16::from_ne_bytes([b[0], b[1]]))
                            .collect()
                    },
                )))

which will go the first path if the allocation is aligned.

Alternatively, this copy could be avoided with some notes in #203

Dominant language
Rust
Stars
125
Forks
17
Avg merge
7h 33m
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from developmentseed/async-tiff

All issues in developmentseed/async-tiff

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.