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

refactor: ckb-script package overhaul #4803

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

xxuejie
Copy link
Collaborator

@xxuejie xxuejie commented Feb 11, 2025

This commit revisits ckb-script package, it re-architects the whole data flow within ckb-script, to make it simpler and more maintainable

What problem does this PR solve?

Issue Number: close #xxx

Problem Summary:

What is changed and how it works?

Proposal: xxx

What's Changed:

Related changes

  • PR to update owner/repo:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code ci-runs-only: [ quick_checks,linters ]

Side effects

  • Performance regression
  • Breaking backward compatibility

Release note

None: Exclude this PR from the release note.
Title Only: Include only the PR title in the release note.
Note: Add a note under the PR title in the release note.

@xxuejie xxuejie requested a review from a team as a code owner February 11, 2025 03:48
@xxuejie xxuejie requested review from zhangsoledad, quake and chenyukang and removed request for a team February 11, 2025 03:48
chenyukang
chenyukang previously approved these changes Feb 11, 2025
script/src/scheduler.rs Outdated Show resolved Hide resolved
eval-exec
eval-exec previously approved these changes Feb 11, 2025
driftluo
driftluo previously approved these changes Feb 11, 2025
zhangsoledad
zhangsoledad previously approved these changes Feb 11, 2025
@zhangsoledad zhangsoledad self-requested a review February 11, 2025 15:06
@xxuejie xxuejie dismissed stale reviews from zhangsoledad, driftluo, and eval-exec via b95c684 February 12, 2025 02:01
@xxuejie xxuejie force-pushed the ckb-script-overhaul branch from 3595333 to b95c684 Compare February 12, 2025 02:01
script/src/scheduler.rs Outdated Show resolved Hide resolved
eval-exec
eval-exec previously approved these changes Feb 12, 2025
quake
quake previously approved these changes Feb 12, 2025
@xxuejie xxuejie dismissed stale reviews from quake and eval-exec via 416cf43 February 13, 2025 06:31
This commit revisits ckb-script package, it re-architects the whole data
flow within ckb-script, to make it simpler and more maintainable
In the original refactoring work, the verifying context data is kept in
`Arc<SgData>` structure, which contains `Arc<TxData>`, which then contains
`Arc<ResolvedTransaction>`. Accessing a specific field on a CKB transaction
requires traversing through 3 `Arc` structures, which would be 3 levels of
indirection.

Benchmarks show that those nested memory indirections cost us ~3% of transaction
verifying performance, our best guess is that the nested indirections result in
enough cache misses to cause the differences.

This commit changes the code so instead of nested `Arc`s, we now use flattened
structs that then contain a series of `Arc`s. Now at most one `Arc` would get in
the way to access a specific field of the CKB transaction to verify.

Note that `consensus` and `tx_env` still hids in 2 nested levels of `Arc`, here we
are balancing the nested levels of `Arc`, and the number of `Arc`s contained in the
flattend `TxData` and `SgData` structure. Right now we work under the assumption that
if consensus parameters are required indeed, a nested level of indirection won't be
the bottleneck. However, this might or might not change in the future, when it becomes
a problem, we will revisit the tradeoff then.
@xxuejie xxuejie force-pushed the ckb-script-overhaul branch from 416cf43 to 8b6654a Compare February 13, 2025 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
m:vm t:enhancement Type: Feature, refactoring.
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

6 participants