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

Clean up bytes module #3549

Closed
Tracked by #3489
kt3k opened this issue Aug 19, 2023 · 5 comments · Fixed by #3589
Closed
Tracked by #3489

Clean up bytes module #3549

kt3k opened this issue Aug 19, 2023 · 5 comments · Fixed by #3589
Assignees

Comments

@kt3k
Copy link
Member

kt3k commented Aug 19, 2023

Most APIs of bytes module are simple functions that work on Uint8Arrays, but only BytesList has exceptional design and purpose.

BytesList was introduced for optimizing readDelim method of io (then bufio) module. #867 It was more like internal utility for optimization rather than a public API.

I think we should deprecate this API before stabilizing std/bytes (but we might better to check the actual usages in the ecosystem)

part of #3489

@kt3k kt3k mentioned this issue Aug 19, 2023
16 tasks
@lino-levan
Copy link
Contributor

I use BytesList quite a lot as it's a pretty nice way of doing operations on a group of Uint8Arrays. I'm not sure I support deprecating it.

@kt3k
Copy link
Member Author

kt3k commented Aug 22, 2023

@lino-levan Could you share your use cases?

@lino-levan
Copy link
Contributor

I use it a lot for efficient encoding. It doesn't look super used in the ecosystem outside of some of my repos and iuioiua's r2d2, but maybe that's just due to it's nature. I'm for keeping this around.

@iuioiua
Copy link
Contributor

iuioiua commented Aug 24, 2023

I only use BytesList for concatenating Uint8Arrays. According to benchmarks, BytesList and concat() are equal in performance when the amount of Uint8Arrays to be concatenated is low. However, as you increase the amount of Uint8Arrays, BytesList becomes more and more slower than concat(). Beyond performance, I prefer functions over classes and methods because they're simpler. In fact, I will switch from using BytesList to using concat(), irrespective of whether ByteList gets deprecated.

Benchmark:

import { BytesList } from "https://deno.land/std@0.200.0/bytes/bytes_list.ts";
import { concat } from "https://deno.land/std@0.200.0/bytes/concat.ts";

const ARRAYS_LENGTH = 100;
const DATA_LENGTH = 100;

function genData(length: number) {
  const data = new Uint8Array(length);
  crypto.getRandomValues(data);
  return data;
}

const arrays = Array.from(
  { length: ARRAYS_LENGTH },
  () => genData(DATA_LENGTH),
);

Deno.bench("ByteList", { baseline: true }, () => {
  const lines = new BytesList();
  for (const array of arrays) lines.add(array);
  lines.concat();
});

Deno.bench("concat", () => {
  concat(...arrays);
});

Results:

benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
--------------------------------------------------------------- -----------------------------
ByteList        7.42 µs/iter     134,789.1   (6.38 µs … 186.42 µs)   7.12 µs  10.17 µs  36.58 µs
concat          2.82 µs/iter     355,109.3     (2.67 µs … 3.33 µs)   2.86 µs   3.33 µs   3.33 µs

summary
  ByteList
   2.63x slower than concat

I'm +1 for deprecating BytesList. My main concern would be: For each BytesList method, what must a dev use instead if BytesList were to be deprecated?

@johnspurlock
Copy link

Heads up - this seems to have broken DelimiterStream: see #3609

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 a pull request may close this issue.

5 participants