Repository navigation
breaking: new wire format, and reducer and reviver changes #246
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
Draft
elliott-with-the-longest-name-on-github
wants to merge
20
commits into
main
from
elliott/new-wire-format
+5,087
−1,052
Draft
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
153c304
breaking: new wire format for stringify and parse
elliott-with-the-longest-name-on-github cb278ab
chore: split the tree-format changeset into one per change
elliott-with-the-longest-name-on-github f39b841
fix: reject a promise result that is a thenable, however it was written
elliott-with-the-longest-name-on-github 4726b32
breaking: reducers only see objects; revivers are called once, with t…
elliott-with-the-longest-name-on-github ce7cc07
perf: mark values still being read in their slot instead of tracking …
elliott-with-the-longest-name-on-github 2d9f25b
docs: boxes and views that refer to themselves are rejected
elliott-with-the-longest-name-on-github 1e91d10
refactor: find a promise's path by walking again with the writer
elliott-with-the-longest-name-on-github 041ac36
style: collapse a few single-statement blocks in parse and stringify
elliott-with-the-longest-name-on-github 4506cf1
refactor: type the async-only state honestly instead of casting null
elliott-with-the-longest-name-on-github cb45a64
chore: explain why path_to_root may clear the writer's state
elliott-with-the-longest-name-on-github fbc8d1b
chore: clearer comments on numbering, references and inlined loops; o…
elliott-with-the-longest-name-on-github dbebe9c
chore: fix benchmark imports
elliott-with-the-longest-name-on-github fb27932
chore: add uneval benchmarks for plain rows
5cdbef2
chore: benchmark plain rows followed by a Map of every row
4c209c2
shorten labels so they fit the table printed by pnpm bench
0656237
drop two benchmarks that existing ones already cover
ff0c46b
chore: add parse benchmarks, and benchmarks for shared and custom values
elliott-with-the-longest-name-on-github d8a023b
chore: remove scratch files committed by mistake
elliott-with-the-longest-name-on-github 2c6d263
chore: shorten a benchmark label to fit the table
elliott-with-the-longest-name-on-github 4449f1c
perf: splice base64 text in after JSON.stringify instead of having it…
elliott-with-the-longest-name-on-github File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': minor | ||
| --- | ||
|
|
||
| feat: `stringifyAsync` rejects with the first failure it sees, without waiting for promises that come before it in the value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: a value written by `stringifyAsync` is parsed with a promise wherever it had one, where earlier versions put what the promise resolved to | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: a reviver named after a built-in type such as `Map` or `Set` is given the whole of what it was written as, for example every key and value of a `Map`, instead of only the first |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: the `toISOString` and `fromISOString` operations are replaced by `timeOf(date)`, which returns the time in milliseconds, and `fromTime(time)`, which creates a Date from it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: a reviver named `Date` is given the time in milliseconds (`NaN` for an invalid date) instead of an ISO string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: reducers passed to `stringify` and `stringifyAsync` are only called on objects and functions. Strings, numbers, booleans, BigInts, `null` and `undefined` are always written as themselves |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': minor | ||
| --- | ||
|
|
||
| feat: add a `references: false` option to `parse`, `unflatten`, `stringify` and `stringifyAsync` that rules out repeated and cyclical references |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: a reviver named `RegExp` is given `[source, flags]` instead of only the source |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: `stringify` and `stringifyAsync` can read a property of the value more than once |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: `stringify` and `stringifyAsync` skip an object's symbol keys, as `JSON.stringify` does, instead of throwing `Cannot stringify POJOs with symbolic keys`. `uneval` still throws | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should just skip them in |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: `stringify` and `stringifyAsync` write a new format, which is faster to write and to parse and compresses better. Payloads written by earlier versions can no longer be parsed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'devalue': major | ||
| --- | ||
|
|
||
| breaking: a reviver is called once, with its whole payload. A custom value whose payload refers back to the value itself now throws `Invalid circular reference`, where before its reviver was called early with the payload so far and then again. For types whose values can contain themselves, pass a two-stage reviver, `{ create, fill }`: `create` makes the value before its payload is read, and `fill` is given the value and the whole payload |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { parse, stringify } from '../../src/index.js'; | ||
| import { records } from '../records.js'; | ||
| import { reducers, revivers, shared_records, shared_vectors, vectors } from '../shapes.js'; | ||
| import { fastest_test } from '../utils.js'; | ||
|
|
||
| /** | ||
| * Parses what this version's `stringify` writes for `value` | ||
| * @param {string} label | ||
| * @param {any} value | ||
| * @param {number} iterations | ||
| * @param {boolean} [custom] whether `value` has custom types in it | ||
| */ | ||
| function benchmark(label, value, iterations, custom = false) { | ||
| const json = custom ? stringify(value, reducers) : stringify(value); | ||
| const r = custom ? revivers : undefined; | ||
|
|
||
| return { | ||
| label: `parse: ${label}`, | ||
| async fn() { | ||
| for (let i = 0; i < iterations; i += 1) parse(json, r); | ||
| return fastest_test(3, () => { | ||
| for (let i = 0; i < iterations; i += 1) parse(json, r); | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| export default [ | ||
| benchmark('small object', { id: 42, name: 'Jane Smith', roles: ['admin', 'editor'] }, 100000), | ||
| benchmark('100 records', records(100), 500), | ||
| benchmark('1000 records', records(1000), 50), | ||
| benchmark('1000 records, shared authors', shared_records(1000), 50), | ||
| benchmark( | ||
| 'unique short strings', | ||
| Array.from({ length: 1000 }, (_, i) => `item-${i}`), | ||
| 2000 | ||
| ), | ||
| benchmark('repeated long strings', Array(1000).fill('x'.repeat(256)), 200), | ||
| benchmark( | ||
| 'string Map', | ||
| new Map(Array.from({ length: 1000 }, (_, i) => [`key-${i}`, `value-${i}`])), | ||
| 500 | ||
| ), | ||
| benchmark( | ||
| '1000 numbers', | ||
| Array.from({ length: 1000 }, (_, i) => i / 7), | ||
| 1000 | ||
| ), | ||
| benchmark('2000 custom values', vectors, 50, true), | ||
| benchmark('2000 refs, 200 custom values', shared_vectors, 50, true) | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.