Skip to content

Improve DecodeBuffer::repeat performance again #18

@KillingSpark

Description

@KillingSpark

With the Pullrequest from @paolobarbolini the draining of the decodebuffer has improved a lot (because it now has no memmove anymore which was part of the Vec::drain(..)). As a consequence we now have a 2x increase in memcpys in the sequence execution.

It should be possible to get the best of both worlds. I will have to implement a custom ringbuffer though.

Most operations this needs to support are pretty trivial:

  1. push()
  2. extend()
  3. len()/capacity()
  4. get_slices()
  5. clear()
  6. reserve()
  7. as_slices()

The only non-trivial part is the optimization we need in the sequence execution (which is implemented in DecodeBuffer::repeat).
We need a kind of equivalent of Vec's extend_from_within. Which is a bit harder to do for A Ringbuffer.

fn extend_from_within(offset, match_length) {
    // This is expected to not need to do anything after the first few calls. 
    // The decodebuffer should grow to a certain capacity
    // at which it can hold all the decoded data until the next drain.
    self.reserve(match_length);

    let (s1, s2) = self.slices();
    let (match1, match2) = figure_out_which_regions_need_copying(offset, match_length, s1, s2);

    let (f1, f2) = self.free_capacity();
    // Now the compilcated part that I am too lazy to prototype this evening:
    // copy match1 and match2 into f1 and f2. 
    // With the call to reserve these are guaranteed to have enough space to hold them.
    // In the expected case all that is happening here is a memcpy from match1 into f1 and we are done
    //
    // But since this is a Ringbuffer we need to deal with the occasional fractioning of these regions
    // In the worst case this results in 4 memcpys but that should be quite rare
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions