Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

JSON stringify types over the ffi #131

Merged
merged 10 commits into from
Oct 7, 2024

Conversation

KendallWeihe
Copy link
Contributor

I JSON-stringified Offering's over the wasm FFI & ran some experiments

  • Reduced bundle size by 100KB
  • Increased test vector duration from 35ms to 32ms

It is surprisingly faster! I wouldn't have guessed that.

Copy link

github-actions bot commented Oct 2, 2024

TBD Spec Test Vectors Report (tbdex-rs)

Total Test VectorsTotal Test Cases✅ Passed❌ Failed⚠️ Skipped
109900
ℹ️ 9 out of 10 test vectors passed successfully.

❌ Missing Vectors (1)

These are test vectors without any test cases.
FeatureName
Protocolparse_orderinstructions

Automatically generated at: 2024-10-07T13:56:29.475Z

rule: SubmissionRequirementRule;
};

// todo make enum
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would want to make this and Optionality above actual ts enums, or type unions to be more exact

Copy link

github-actions bot commented Oct 2, 2024

TBD Spec Test Vectors Report (tbdex-core-kt)

Total Test VectorsTotal Test Cases✅ Passed❌ Failed⚠️ Skipped
10101000
✅ All test vectors passed
Automatically generated at: 2024-10-07T13:59:50.909Z

@KendallWeihe KendallWeihe marked this pull request as ready for review October 2, 2024 23:02
@KendallWeihe KendallWeihe changed the title Prototype JSON stringifying all Offering over FFI JSON stringify types over the ffi Oct 2, 2024
Copy link
Contributor

@nitro-neal nitro-neal left a comment

Choose a reason for hiding this comment

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

awesome job

throw tbdexError(error);
}
};
static fromJSONString = (json: string): Exchange => {
Copy link
Contributor

Choose a reason for hiding this comment

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

may be a bit cleaner something like this (from chad)

  const obj = JSON.parse(json);

  const createInstance = (ClassType: any, objPart?: any) => 
    objPart ? new ClassType(objPart.metadata, objPart.data, objPart.signature) : undefined;

  const rfq = createInstance(Rfq, obj.rfq);
  const quote = createInstance(Quote, obj.quote);
  const order = createInstance(Order, obj.order);
  const orderInstructions = createInstance(OrderInstructions, obj.orderInstructions);
  const cancel = createInstance(Cancel, obj.cancel);
  const orderStatuses = obj.orderStatuses
    ? obj.orderStatuses.map((x: any) => createInstance(OrderStatus, x))
    : undefined;
  const close = createInstance(Close, obj.close);

  return new Exchange(rfq, quote, order, orderInstructions, cancel, orderStatuses, close);
}

@KendallWeihe KendallWeihe merged commit 15d44c4 into main Oct 7, 2024
20 checks passed
@KendallWeihe KendallWeihe deleted the kendall/experiment-json-stringify-wasm-ffi branch October 7, 2024 14:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants