Skip to content

Remove/justify clone() across the codebase #4668

@lferrigno

Description

@lferrigno

Campaign: Remove/justify clone() across the codebase

We want to reduce unnecessary clones in hot paths and make intentional clones explicit.

Goals

  • Every clone() must be reviewed.
  • If a clone is removed → commit the change and check it off here.
  • If a clone is kept → add a comment above the line with
    // ok-clone: <reason>.

Sub-issues

  • VM & execution (crates/vm/**)
  • Sequencer / L2 core (crates/l2/**)
  • Networking P2P (crates/networking/p2p/**)
  • Networking RPC (crates/networking/rpc/**)
  • Blockchain core (crates/blockchain/**)
  • Storage & trie (crates/storage/**, crates/common/trie/**)
  • Common types/serde (crates/common/types/**, crates/common/serde_utils.rs)
  • CLI/tooling/docs (cmd/**, tooling/**, docs/**)

Process

  1. Locate all clone() calls.
  2. Classify:
    • Unnecessary → refactor to avoid copying (&T, Arc<T>, Cow, copied(), etc).
    • Required → keep and mark with // ok-clone: <reason>.
  3. Submit small PRs per subsystem.

Examples

// ok-clone: needed to increment Arc refcount
let x = arc_value.clone();

// ok-clone: async move requires owned value
tokio::spawn(do_work(config.clone()));

// ok-clone: serde requires owned String
let json = serde_json::to_string(&data.clone())?;

Metadata

Metadata

Assignees

Labels

L1Ethereum clientrustPull requests that update rust codetech debtRefactors, cleanups, etc

Type

No type

Projects

Status

Blocked

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions