CKB Pulse

All lessons · CKB node, RPC and indexer · Start here · Glossary

Reuse one CkbRpcClient across a loop instead of building one per itemWorkingFrom one fix

From one fix · Check: right · Checked 2026-11-19

Constructing a ckb_sdk CkbRpcClient (CkbRpcClient::with_builder) loads the TLS root store, about 6 ms of CPU each time. In Fiber's watchtower, building one per watched channel made a round over 11,496 channels take 93 to 115 s; building one client before the loop and passing &CkbRpcClient cut it to 5 to 7 s.

Why it matters: Building a new ckb_sdk CkbRpcClient for every item reloads the TLS root store each time, about 6 ms of CPU per item. Over 11,496 watched channels that stretched one watchtower round from 5 to 7 s to 93 to 115 s.

Pattern

Prefer
let ckb_client = CkbRpcClient::with_builder(&rpc_url, |builder| { builder.timeout(CKB_RPC_TIMEOUT).no_proxy() }) (built once, before the for loop over watched channels)

Taken from the commit, shortened.

Concepts
Network and RPC reliability
Evidence
From one fix: from one project, checked against its commit
First seen
2026-11-03
Last changed
2026-11-03
Last checked
2026-11-19
Check against the commit
right: the lesson follows from its commit and still holds in the code today

Sources (1)

More about CKB node, RPC and indexer

All 45 in this topic

Do you maintain a project this lesson came from? Confirm or correct it

Cite this lesson
LusoCryptoLabs, "Reuse one CkbRpcClient across a loop instead of building one per item", CKB lessons, https://pulse.lusocryptolabs.com/learned/node/reuse-one-ckbrpcclient-across-a-loop-instead-of-building-one, CC BY 4.0, last changed 2026-11-03.

Drawn from public commits and checked against the commit each one came from and the project's code today. Read the source before you rely on one. Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. Want a lesson changed or removed? Open an issue.