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

feature: Migrate zero copy API and streaming API into master branch #291

Open
fxamacker opened this issue Jun 16, 2021 · 4 comments
Open
Assignees
Labels

Comments

@fxamacker
Copy link
Owner

Add API that uses zero copy to boost performance.
Add streaming mode decoder and encoder.

@fxamacker fxamacker self-assigned this Jun 16, 2021
@bijwaard
Copy link

bijwaard commented Sep 22, 2021

Hi fxamacker,
I am trying to get the stream_decoder API (from the stream-mode branch) working but have no clue how to use floats in the stream. I expected to see a floats in the API, but mainly find int's, arrays and maps. Are you planning to add floats while merging the stream-mode branch?
Kind regards,
Dennis

@bijwaard
Copy link

bijwaard commented Sep 23, 2021

Hi Faye,
While creating my stream-decoder, I noticed that most decode functions use a return for the result. It may be more efficient to use a pointer-argument for the larger types (e.g. strings and byte arrays), so you can also update an existing element without new memory allocation when the element is big enough? It may also save an extra copy for the int64/float64 types.

My stream-decoder now looks like this (decoding floats does not yet compile...), I use a pointer to the rtd_msg struct to avoid creating a new one for every message:

type rtd_msg struct {
  rtd_id uint64
  values []float64
}

func DecodeRTD(buf []byte,r *rtd_msg) error {
  sd:=cbor.NewStreamDecoder(bytes.NewReader(buf))
  var err error
  var l uint64
  _, err = sd.DecodeArrayHead()
  if r.rtd_id,err = sd.DecodeUint64(); err != nil {
    return err
  }

  l, _ = sd.DecodeArrayHead()
  // FIXME: increase array if necessary if l>len(r.values) ...
  for i:=uint64(0);i<l;i++ {
    if r.values[i],err = sd.DecodeFloat(); err!=nil {
      return err
    }
  }
  return nil
}

Kind regards,
Dennis

@fxamacker
Copy link
Owner Author

Hi fxamacker, I am trying to get the stream_decoder API (from the stream-mode branch) working but have no clue how to use floats in the stream. I expected to see a floats in the API, but mainly find int's, arrays and maps. Are you planning to add floats while merging the stream-mode branch? Kind regards, Dennis

Hi @bijwaard,

The feature/stream-mode branch was developed for Cadence to improve performance.

Cadence didn't need floats, so the feature to stream floats wasn't added. I don't have a specific timeline for merging this branch into main yet. Before merging to main I'd definitely like to add stream support for floats and maps.

@bijwaard
Copy link

bijwaard commented Oct 11, 2021

Hi Faye,
I'm looking forward to the merged speed-up for floats! For now your library already helps me to decode electrical measurements roughly twice as fast as my earlier cbor decoder in Python. The C++ counterpart is still way faster since it has everything pre-allocated...
Kind regards,
Dennis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants