-
Notifications
You must be signed in to change notification settings - Fork 74
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
fix(marshal): Add a smaller and more efficient passable encoding #1594
Conversation
@@ -328,11 +451,17 @@ export const makeEncodePassable = (encodeOptions = {}) => { | |||
encodeRemotable = (rem, _) => Fail`remotable unexpected: ${rem}`, | |||
encodePromise = (prom, _) => Fail`promise unexpected: ${prom}`, | |||
encodeError = (err, _) => Fail`error unexpected: ${err}`, | |||
xxx = false, |
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.
We need a name for the smaller encoding and this property opting in to it, and ideally also a name for the current encoding. I don't have any good suggestions at the moment, so 🚲🏠 away!
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.
Some thoughts:
oldAndBusted
vsnewHawtness
tired
vswired
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.
escapism
vsrealism
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.
legacyOrdered
vs compactOrdered
?
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.
For what it's worth, I don't think there's a fundamental aspect to the new encoding other than translation of rank ordering into lexicographic ordering (a feature which it shares with the current encoding). And the key detail differentiating the two is that the current encoding applies escaping to array elements (causing blowup for deep structures) while the new one applies escaping to strings and transitively to symbols, which are the only types that can contain characters confusable with array encoding delimiters and as scalars are immune to the blowup issue.
"Compact" is accurate in a relative sense, but keep in mind that we're still using text rather than raw octets.
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.
So legacyOrdered
vs compactOrdered
is fine?
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.
I would think just "legacy"
vs. "compact"
, e.g. makeEncodePassable({ format: "compact" })
. What significance of "ordered" am I missing?
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.
Neither smallcaps nor its predecessor are order preserving. The main feature of both the formats we're naming here is that they are.
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.
Ah, so IIUC you're thinking about something like makeMarshal(convertValToSlot, convertSlotToVal, { serializeBodyFormat: "compactOrdered" })
and wanting "compactOrdered" to be used everywhere. 👍
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.
yes, exactly.
Hopefully fixes Agoric/agoric-sdk#2589 , yes? |
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.
Sorry this took so long!
Looking forward to using this! I think I can start making use of this soon.
@@ -328,11 +451,17 @@ export const makeEncodePassable = (encodeOptions = {}) => { | |||
encodeRemotable = (rem, _) => Fail`remotable unexpected: ${rem}`, | |||
encodePromise = (prom, _) => Fail`promise unexpected: ${prom}`, | |||
encodeError = (err, _) => Fail`error unexpected: ${err}`, | |||
xxx = false, |
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.
legacyOrdered
vs compactOrdered
?
const encodeString = xxx | ||
? encodeStringWithEscapes | ||
: encodeStringWithoutEscapes; | ||
const encodeArray = xxx ? encodeArrayWithoutEscapes : encodeArrayWithEscapes; |
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.
I was initially very confused until I realized that encodeStringWithEscapes
goes with encodeArrayWithoutEscapes
and encodeStringWithoutEscapes
goes with encodeArrayWithEscapes
. Once we have a name for xxx
, then perhaps use that in these function names so it is less surprising which goes with which.
Btw @gibson042 , I reviewed it as if it is Ready For Review. Is there a reason it is still Draft? |
Any idea why CI didn't complete? |
Yes, I think we can make that claim.
I consider it a draft until we settle on a name.
Pushed to kick CI, and I can also rebase on master if that won't disrupt review. |
Please do rebase to master, thanks. |
0cee48b
to
402bb08
Compare
This provides better differention w.r.t. smallcaps, cf. #1594 (comment)
This provides better differention w.r.t. smallcaps, cf. #1594 (comment)
c97046e
to
f2c1df6
Compare
Updated to use "legacyOrdered" and "compactOrdered" names—so this PR is no longer a draft! |
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.
LGTM, thanks!
(If possible, would be nice to see this merged before tomorrow's ocapn mtg)
Returning to draft because I found that the new format needs more handling for output from functions provided to import "@endo/init";
import { Far } from "@endo/far";
import { makeMarshal, makeEncodePassable } from "@endo/marshal";
const r0 = Far("Foo");
const data = harden([r0, r0, "."]);
const safeEncodeRemotable = r => "r0";
const unsafeEncodeRemotable = r => "r 0";
const baseOptions = { format: "compactOrdered" };
console.log({
safeEncoding: makeEncodePassable({ ...baseOptions, encodeRemotable: safeEncodeRemotable })(data),
unsafeEncoding: makeEncodePassable({ ...baseOptions, encodeRemotable: unsafeEncodeRemotable })(data),
});
/* =>
{
safeEncoding: '~^r0 r0 s. ',
unsafeEncoding: '~^r 0 r 0 s. '
}
*/ |
@@ -346,7 +567,7 @@ export const makeEncodePassable = (encodeOptions = {}) => { | |||
return encodeBinary64(passable); | |||
} | |||
case 'string': { | |||
return `s${passable}`; | |||
return `s${encodeStringSuffix(passable)}`; | |||
} | |||
case 'boolean': { | |||
return `b${passable}`; |
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.
While we're making changes, should we also replace "btrue" and "bfalse" with e.g. "bt" and "bf"?
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.
b1
and b0
?
Could we provide it such a decode function?
…On Wed, Sep 13, 2023 at 5:11 AM Richard Gibson ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In packages/marshal/src/encodePassable.js
<#1594 (comment)>:
> + } else if (format === 'compactOrdered') {
+ formatPrefix = '~';
+ encodeStringSuffix = encodeCompactStringSuffix;
+ encodeArray = encodeCompactArray;
+ } else {
+ Fail`Unrecognized format: ${q(format)}`;
+ }
+ const encodeRemotable = makeEncodeRemotable(
+ unsafeEncodeRemotable,
+ encodeStringSuffix,
+ );
+ const encodePromise = makeEncodePromise(
+ unsafeEncodePromise,
+ encodeStringSuffix,
+ );
+ const encodeError = makeEncodeError(unsafeEncodeError, encodeStringSuffix);
This double-escapes the contents of any embedded string (such as for the
error message), but I don't see a good alternative. In particular,
asserting that unsafeEncodeError produced an independently valid encoding
that needs no further escaping would be awkward because this code doesn't
have access to any caller-provided decode functions for embedded
remotables/promises/errors.
—
Reply to this email directly, view it on GitHub
<#1594 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACC3TAZEZWGDV3GPWD3SW3X2GPH7ANCNFSM6AAAAAAYMMXCXA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
85a996c
to
a99748a
Compare
Any chance we could get a neighboring This document would also be a good place to mention that the
|
I expect this to be per collection to preserve sort order between entries, so it could be in the vc metadata. |
This provides better differention w.r.t. smallcaps, cf. #1594 (comment)
a99748a
to
8f93653
Compare
This provides better differention w.r.t. smallcaps, cf. #1594 (comment)
8f93653
to
17601ac
Compare
Fixes failures on Node.js v14
This provides better differention w.r.t. smallcaps, cf. #1594 (comment)
…motable/promise/error callbacks
…ble/promise/error compactOrdered encodings (rather than forcing everything through string encoding)
… remotable/promise/error compactOrdered encodings
* Introduce a short-circuiting `getSuffix` (for skip=0). * Extend "skip" to `innerDecode`, `decodeBinary64`, `decodeRecord`, and `decodeTagged`.
17601ac
to
70bcca3
Compare
Fixes #1349
Open questions:
bfalse
→bf
/btrue
→bt
(booleans) and/orp1:0
→o
(0n)?!
/_
?{ "metasyntactic variables": ["foo", "bar", "baz"], tab: "\t", null: "\0" }
would change as follows if we used tab-termination rather than space-termination: