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

docs: add docs for tx deps prefetching optimisation #3499

Closed
wants to merge 8 commits into from

Conversation

Dhaiwat10
Copy link
Member

@Dhaiwat10 Dhaiwat10 commented Dec 24, 2024

Release notes

In this release, we:

  • Added documentation for a contract call optimisation technique via pre-fetching dependencies which can result in as much as 2x faster transactions for users.

Summary

This PR adds documentation explaining how pre-fetching contract call/transaction dependencies can speed up transactions for users, and a recommended implementation for devs.

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@Dhaiwat10 Dhaiwat10 added the docs Requests pertinent to documentation label Dec 24, 2024
@Dhaiwat10 Dhaiwat10 self-assigned this Dec 24, 2024
Copy link

vercel bot commented Dec 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuels-template ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 24, 2024 5:34pm
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 24, 2024 5:34pm
ts-docs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 24, 2024 5:34pm

Copy link

codspeed-hq bot commented Dec 24, 2024

CodSpeed Performance Report

Merging #3499 will degrade performances by 44.35%

Comparing dp/tx-prefetch-deps-docs (85f738f) with master (41c72fb)

Summary

❌ 1 regressions
✅ 17 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark master dp/tx-prefetch-deps-docs Change
should successfully conduct a custom transfer between wallets (x20 times) 50.3 ms 90.3 ms -44.35%

Copy link
Contributor

@danielbate danielbate left a comment

Choose a reason for hiding this comment

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

Nice work Dhai, do you think this could have it's own section in the docs around front-end optimisations? And I think those diagrams could do with some more love, maybe generate them with a flow chart tool.

apps/docs/src/guide/contracts/optimising-contract-calls.md Outdated Show resolved Hide resolved
apps/docs/src/guide/contracts/optimising-contract-calls.md Outdated Show resolved Hide resolved
apps/docs/src/guide/contracts/optimising-contract-calls.md Outdated Show resolved Hide resolved
apps/docs/src/guide/contracts/optimising-contract-calls.md Outdated Show resolved Hide resolved
apps/docs/src/guide/contracts/optimising-contract-calls.md Outdated Show resolved Hide resolved

This can be mitigated by preparing the contract call _before_ the user presses 'Submit Transaction'. If the transaction is prepared beforehand, the SDK only has to send the transaction to the network and wait for it to be confirmed. This reflects the actual speed of the chain to the user.

You can experience this yourself by trying out this [demo](https://fuel-wallet-prefetch-experiment-75ug.vercel.app/).
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm should this be brought inside the SDK? Is it more beneficial for this to live inside a snippet?

Copy link
Member Author

Choose a reason for hiding this comment

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

This = demo or the hook?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

@danielbate danielbate Dec 24, 2024

Choose a reason for hiding this comment

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

The demo, usually we don't have any external deps for the docs, the links is from an external projects on Dhai's github


We recommend creating a `usePrepareContractCall` hook:

```tsx
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this all be in a snippet for forwards compatibility?

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 could be; but that would mean us having to create a new project for snippets since this is a React snippet. In the interest of speed and considering how important this info is for our ecosystem projects, I think it is fine if we create the snippets in a separate PR. Nick wants us to announce this asap on Twitter

Copy link
Member

Choose a reason for hiding this comment

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

As much as we love teaching devs how to fetch data in React, we still have two more weeks of code freeze. 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree, this is not about teaching people how to fetch data in React. It's about the overall idea of preparing contract calls in advance, leading to a faster transaction experience.

About the code freeze, this is not adding any new code. Can we not get this in?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think eliminated is the wrong wording here, as we are instead optimistically preparing the transaction.

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't it makes sense in the context of a tranasction's lifetime for the end user?

Copy link
Member

Choose a reason for hiding this comment

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

@danielbate Agreed, the request is optimistically fetched, not eliminated.

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 is eliminated from the contract call's lifecycle, so I strongly think it is eliminated in that context.

Dhaiwat10 and others added 5 commits December 24, 2024 22:43
Co-authored-by: Daniel Bate <[email protected]>
Co-authored-by: Daniel Bate <[email protected]>
Co-authored-by: Daniel Bate <[email protected]>
Co-authored-by: Daniel Bate <[email protected]>
Co-authored-by: Daniel Bate <[email protected]>
@Dhaiwat10
Copy link
Member Author

@danielbate in the interest of getting this out there and speed; can we proceed with these diagrams for now? I personally think they are ok, but yes we could do better. Also: will we be able to merge/release this now during the code freeze?

Copy link
Contributor

Coverage Report:

Lines Branches Functions Statements
76.33%(+0%) 69.84%(+0%) 74.2%(+0%) 76.34%(+0%)
Changed Files:

Coverage values did not change👌.

Comment on lines +198 to +201
{
text: 'Optimising Contract Calls',
link: '/guide/contracts/optimising-contract-calls',
},
Copy link
Member

Choose a reason for hiding this comment

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

It seems confusing to mix React tips with core contract documentation.

A simple React recipe demoing the example hook may suffice.

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree that this is a React tip. Like I mentioned here: #3499 (comment)

@@ -0,0 +1,106 @@
# Optimizing Contract Calls
Copy link
Member

Choose a reason for hiding this comment

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

We are not optimizing contract calls.

Suggested change
# Optimizing Contract Calls
# Optimizing Contract Estimation in React Apps

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree, the estimation itself isn't optimized - it's just done in advance which leads to faster/optimised contract calls.


The below flowchart shows this entire process:

![Transaction Lifecycle in the SDK without prefetching](../../public/txdep1.png)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I'm hesitant about adding images to the docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why?

@Dhaiwat10 Dhaiwat10 requested a review from danielbate December 24, 2024 18:28
@danielbate
Copy link
Contributor

If there is an immediate need to communicate this to the community, this can be done independently to the TS SDK documentation. Could do this via a Twitter thread with diagrams and stackblitz rather than breaking the code freeze and pushing something we aren't all happy with.

@Dhaiwat10 Dhaiwat10 closed this Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Requests pertinent to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add documentation for tx dependency optimisation technique
3 participants