Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m2/ts-byte-views/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ Public API: the translator's output for byte slices.

## Required

- [Byte slices in locals](/quest/m2/ts-byte-views/locals.md) - a slice local never borrowed mutably is three values
- [Byte slices returned](/quest/m2/ts-byte-views/returns.md) - a function returns a split's parts without an object
- [Byte slices in fields](/quest/m2/ts-byte-views/fields.md) - a private slice field is three fields
28 changes: 0 additions & 28 deletions quest/m2/ts-byte-views/locals.md

This file was deleted.

8 changes: 2 additions & 6 deletions quest/m2/ts-byte-views/returns.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

A translated function that returns a value built of byte slices and scalars, such as
`Result<(&[u8], T), E>`, hands its parts to the caller without an object, and Chrome's
varint and frame decode on `just ts bench` are faster than with
[locals](/quest/m2/ts-byte-views/locals.md) alone, with every differential test passing.
varint and frame decode on `just ts bench` are faster than with slices held as parts in
locals alone, with every differential test passing.

## Plan

Expand All @@ -25,7 +25,3 @@ sites, and module `let`s measured 0.93x in Chrome.
never delays that read.

Public API: the translator's output for byte slices.

## Required

- [Byte slices in locals](/quest/m2/ts-byte-views/locals.md) - the representation returns hand on
13 changes: 11 additions & 2 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,17 @@ they need.
and encode no slower. A `&[u8; N]`, such as `split_first_chunk`'s chunk, is an
`rt.ByteSlice` too, its bytes read in place: the decode workloads then took 0.72 times
a view's time in Chrome, 0.67 in Firefox, 0.87 in Node, and 0.71 in Bun at the
geometric mean, with the A/A route within 0.03, and encode no slower. Each split still
makes a `ByteSlice` ([byte slices without objects](/quest/m2/ts-byte-views/README.md)).
geometric mean, with the A/A route within 0.03, and encode no slower.
- A local built of byte slices and scalars, in tuples, `Option`s, `Result`s, and
`ControlFlow`s, is a JS value per part: a slice's `data`, `start`, and `length`, and an
enum's variant as a flag, when nothing borrows or writes into it and only std's splits,
`ok_or`, `?`, aggregates, and copies assign it. A read that takes it apart reads its
parts; any other makes its object there, and a local whose object would be made more
often than before stays one. `just ts bench` measured the codec's varint decode at 0.49
times the objects' time in Chrome, 0.57 in Firefox, 0.64 in Node, and 0.56 in Bun at
the geometric mean, and frame decode at 0.61, 0.56, 0.70, and 0.61, with the A/A route
within 0.04 and encode no slower. A parameter, a return, and a field are still a
`ByteSlice` ([byte slices without objects](/quest/m2/ts-byte-views/README.md)).
- A `BTreeMap` is a B+ tree of up to 64 keys a node, O(log n) as std's B-tree is: its
leaves hold the keys and values and link to their neighbors, which iterators walk from
either end, and its branches hold each child's lower bound. A node's slots shift in a
Expand Down
34 changes: 16 additions & 18 deletions ts/fixtures/codec/expected/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,34 @@ import type * as Version from "./lite/version.Version.ts";
/** Run one workload. */
export function run(input: rt.ByteSlice): rt.ByteVec {
const out: rt.ByteVec = new rt.ByteVec();
const _5: [rt.u8, rt.ByteSlice] | undefined = rt.byteSliceSplitFirst(input);
if (_5 !== undefined) {
const op: rt.u8 = _5[0];
const _9: [rt.u8, rt.ByteSlice] | undefined = rt.byteSliceSplitFirst(_5[1]);
if (_9 !== undefined) {
const selector: rt.u8 = _9[0];
if (input.length !== 0) {
const op: rt.u8 = input.data[input.start];
if (input.length - 1 !== 0) {
const selector: rt.u8 = input.data[input.start + 1];
if (op === 0) {
encoded(encodeVarints(_9[1], form(selector), out), out);
encoded(encodeVarints(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), form(selector), out), out);
} else if (op === 1) {
decoded(decodeVarints(_9[1], form(selector), out), out);
decoded(decodeVarints(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), form(selector), out), out);
} else if (op === 2) {
encoded(encodeFrames(_9[1], liteVersion(selector), out), out);
encoded(encodeFrames(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), liteVersion(selector), out), out);
} else if (op === 3) {
decoded(decodeFrames(_9[1], liteVersion(selector), out), out);
decoded(decodeFrames(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), liteVersion(selector), out), out);
} else if (op === 4) {
encoded(encodeGroup(_9[1], liteVersion(selector), out), out);
encoded(encodeGroup(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), liteVersion(selector), out), out);
} else if (op === 6) {
iterate(selector, _9[1], out);
iterate(selector, new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out);
} else if (op === 7) {
decoded(decodeSplit(_9[1], liteVersion(selector), out), out);
decoded(decodeSplit(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), liteVersion(selector), out), out);
} else if (op === 8) {
ordered(_9[1], out);
ordered(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out);
} else if (op === 9) {
rescale(selector, _9[1], out);
rescale(selector, new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out);
} else if (op === 10) {
stamp(_9[1], out);
stamp(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out);
} else if (op === 11) {
interleave(_9[1], out);
interleave(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), out);
} else {
decoded(decodeGroup(_9[1], liteVersion(selector), out), out);
decoded(decodeGroup(new rt.ByteSlice(input.data, input.start + 2, input.length - 2), liteVersion(selector), out), out);
}
return out;
}
Expand Down
8 changes: 4 additions & 4 deletions ts/fixtures/codec/expected/coding/decode.Decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export function isEmpty(self: Decoder): boolean {

/** Read `len` raw bytes. */
export function slice(self: Decoder, len: rt.usize): rt.Result<rt.ByteSlice, DecodeError.DecodeError> {
const _6: [rt.ByteSlice, rt.ByteSlice] | undefined = rt.byteSliceSplitAtChecked(self.buf, len);
if (_6 !== undefined) {
self.buf = _6[1];
return rt.Ok(_6[0]);
const slice_: rt.ByteSlice = self.buf;
if (len <= slice_.length) {
self.buf = new rt.ByteSlice(slice_.data, slice_.start + len, slice_.length - len);
return rt.Ok(new rt.ByteSlice(slice_.data, slice_.start, len));
}
return rt.Err(short(self, len));
}
Expand Down
Loading