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

fix: Provide smallcaps encoding in addition to capData #1282

Merged
merged 5 commits into from
Sep 23, 2022

Conversation

erights
Copy link
Contributor

@erights erights commented Sep 12, 2022

Based on
https://github.com/endojs/endo/blob/38078aec70975d87a0a76918d0ba788e87420581/packages/marshal/src/marshal.js

This key thing about this PR is that the unserializer understands both new smallcaps and old capData protocols, switching between them based on a leading #. The serialized defaults to the old protocol, based on the useSmallcaps option to makeMarshal. With this defaulting to off, everything is trivially green, but that puts us in a position to switch different subsystems on separately as we put in the work to do so. In this PR itself, only test-marshal-smallcaps.js does so.

See #1283 for an experiment of changing the default useSmallcaps to true, to see what breaks. However, be aware that some tests and even some modules in this PR explicitly set useSmallcaps to false, evading this experiment, because they're known to not yet work with smallcaps.

SECURITY CONCERN

Even though our serializer, as of this PR, does not send smallcaps by default, others can, including malformed smallcaps. For capData, we've reviewed the code for robustness in the face of malformed capData. REVIEWERS, please review the unserializer for robustness against malformed smallcaps. If we cannot be confident that we're at least as robust against malformed smallcaps as we were against malformed capData, that would be a reason to delay this PR until we are.

@erights erights self-assigned this Sep 12, 2022
@erights erights force-pushed the markm-dean-smaller-json branch from 06ba80b to 35211a7 Compare September 12, 2022 03:03
@erights erights requested a review from dtribble September 12, 2022 03:07
@erights erights changed the title WIP: Provide smallcaps encoding in addition to capData fix: Provide smallcaps encoding in addition to capData Sep 12, 2022
@erights erights marked this pull request as ready for review September 12, 2022 18:28
@erights
Copy link
Contributor Author

erights commented Sep 12, 2022

Ready for review!

@arirubinstein for some reason, I cannot add you as an official reviewer. Please consider yourself a reviewer anyway. Thanks.

Copy link
Contributor

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only did a quick pass to understand the smallcaps encoding. If I understand it correctly (it would be nice to have a description to the design and/or comparisons between capdata and smallcaps), the main difference with capdata is the way BigInt, remotables/promises and certain specific values are encoded as strings instead of being encoded as qclass "objects".

While I see how this may result in less verbose (and potentially more readable) output, I'm somewhat surprised it'd lead to such an improvement in performance.

packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
@erights
Copy link
Contributor Author

erights commented Sep 12, 2022

I'm somewhat surprised it'd lead to such an improvement in performance.

We have not measured this, and so do not know. I can explain why I expect a big reduction in allocations, but my pre-measurement intuitions are often wrong. @dtribble , we need to measure this!

The measured increase in performance was Agoric/agoric-sdk#6174 + #1280 . @dtribble measured this, but only for pattern matching. I suspect that at least the endo-level changes generalize, but again we should be skeptical until we measure. We need to more realistically measure this!

@erights
Copy link
Contributor Author

erights commented Sep 12, 2022

If I understand it correctly (it would be nice to have a description to the design and/or comparisons between capdata and smallcaps),

Yes. (FWIW, I did not expect us to decide today to put this into review immediately, or I would have been more ready. But yes, this needs to be written.)

the main difference with capdata is the way BigInt, remotables/promises and certain specific values are encoded as strings instead of being encoded as qclass "objects".

Yes. This means that strings themselves do not always encode as the same string, which also requires that we hilbert the string dimension.

@erights erights force-pushed the markm-dean-smaller-json branch 2 times, most recently from 92f1e15 to 81126ae Compare September 13, 2022 01:08
Copy link
Contributor

@mhofman mhofman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy over from #1284 (review)

packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
@erights erights force-pushed the markm-dean-smaller-json branch from a5de158 to a4f6fe0 Compare September 13, 2022 19:12
packages/captp/src/captp.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToCapData.js Outdated Show resolved Hide resolved
packages/marshal/src/types.js Outdated Show resolved Hide resolved
packages/marshal/src/marshal.js Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/marshal.js Outdated Show resolved Hide resolved
packages/marshal/src/marshal.js Outdated Show resolved Hide resolved
packages/marshal/src/marshal.js Outdated Show resolved Hide resolved
packages/marshal/src/marshal.js Show resolved Hide resolved
packages/marshal/src/marshal.js Show resolved Hide resolved
@erights erights force-pushed the markm-dean-smaller-json branch 2 times, most recently from de9ad19 to 0a5739f Compare September 17, 2022 04:55
@erights
Copy link
Contributor Author

erights commented Sep 19, 2022

All done. PTAL

Copy link
Contributor

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except for verification that each decoded object property name is a string.

We should also create a ticket to update agoric-sdk get-flattened-publication.sh for decoding smallcaps after this lands.

packages/marshal/src/marshal.js Outdated Show resolved Hide resolved
packages/marshal/src/marshal.js Show resolved Hide resolved
packages/marshal/src/marshal.js Outdated Show resolved Hide resolved
packages/marshal/src/marshal.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
@erights erights force-pushed the markm-dean-smaller-json branch from 86018a7 to 8108191 Compare September 23, 2022 01:59
@erights
Copy link
Contributor Author

erights commented Sep 23, 2022

Looks good except for verification that each decoded object property name is a string.

Note that passStyleOf(x) === 'tagged' and makeTagged(tag, payload) both validate that the tag is a string, so marshal doesn't need to.

@erights erights force-pushed the markm-dean-smaller-json branch from f0e5e87 to ae8d7e6 Compare September 23, 2022 02:39
@erights
Copy link
Contributor Author

erights commented Sep 23, 2022

Great suggestions! Done. PTAL.

Copy link
Contributor

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few final nits, but I trust your judgment on all of them. Looks like this is it!

packages/marshal/src/encodeToSmallcaps.js Show resolved Hide resolved
packages/marshal/src/encodeToSmallcaps.js Outdated Show resolved Hide resolved
packages/marshal/src/marshal.js Outdated Show resolved Hide resolved
packages/marshal/src/marshal.js Show resolved Hide resolved
packages/marshal/src/marshal.js Outdated Show resolved Hide resolved
@erights erights merged commit 233dbe2 into master Sep 23, 2022
@erights erights deleted the markm-dean-smaller-json branch September 23, 2022 07:35
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 this pull request may close these issues.

6 participants