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

feat: add asCallsOnlyArg to reduce size of metadata #149

Merged
merged 16 commits into from
Dec 1, 2021
Merged

Conversation

TarikGul
Copy link
Member

@TarikGul TarikGul commented Nov 18, 2021

rel: #111

adds asCallsOnlyArg as an option for getRegistryBase to reduce the size of the metadata.

Todo:

  • Add asCallsOnlyArg to createMetadata, and all residual functions
  • Update examples
  • Add tests for createMetadata

true
);

it('Metadata should decrease in byte size when `asCallsOnlyArg` is true with `createMetadataUnmemoized`', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

For the curious the reason we are testing both the unmemoized and memoized createMetadata is because if the length option for memoizee is changed to less than 3 the function will break for the asCallsOnlyArg, but createMetadataUnmemoized will still work with asCallsOnlyArg. I wanted to isolate them both so we can make sure in the future if any changes are made to either it still works as is for both.

*/
export const createMetadata = memoizee(createMetadataUnmemoized, {
length: 2,
length: 3,
Copy link
Contributor

Choose a reason for hiding this comment

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

briefly reading over the docs (https://github.com/medikoo/memoizee#arguments-length), I wonder if this would work: "Dynamic length behavior can be forced by setting length to false, that means memoize will work with any number of arguments."

I am also a little confused how default args work in terms of length because of this note "Parameters predefined with default values (ES2015+ feature) are not reflected in function's length, therefore if you want to memoize them as well, you need to tweak length setting accordingly".

Either way though sounds like this works, so maybe not worth looking into

Copy link
Member Author

Choose a reason for hiding this comment

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

It works with both false, and length 3 🤔 . false being more flexible, and 3 being strict but with a default arg. I do like the the idea of being strict with 3 though.

Copy link
Contributor

@emostov emostov left a comment

Choose a reason for hiding this comment

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

lgtm - feel free to request me again when you update the examples

const { metadataRpc, registry } = options;
registry.setMetadata(createMetadata(registry, metadataRpc));
const { metadataRpc, registry, asCallsOnlyArg } = options;
registry.setMetadata(createMetadata(registry, metadataRpc, asCallsOnlyArg));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit/Question: Why the suffix "Arg"?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea being that asCallsOnly is the name of the getter for the metadata in polkadot-js so I wanted to make it have a separate name to reduce confusion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the explanation!

Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

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

Looks sane to me offhand :)

@@ -45,7 +45,26 @@ async function main(): Promise<void> {
'state_getRuntimeVersion'
);

// Create Polkadot's type registry.
/**
* Create Polkadot's type registry.
Copy link
Member Author

Choose a reason for hiding this comment

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

@emostov This is what i wrote for the examples. Let me know if you think there should be more than this.

@TarikGul TarikGul merged commit d590b09 into main Dec 1, 2021
@TarikGul TarikGul deleted the tarik-asCallsOnly branch December 1, 2021 16:00
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.

4 participants