For example, running bitcoin-cli getbalance <address>
on an arbitrary, watch-only address takes around 6-7 seconds for a response. Is there any way to improve this?
Besides the fact that this is not how getbalance
works (you don't call it on an address), getbalance
is slow here because it must go through the list of transactions for the addresses in your wallet and sum their outputs to get the balance. If your wallet is very large and has lots of transactions or you are running bitcoind on low powered hardware, this could take a long time.
How do API services like Blockchain return balance details almost instantaneously? Each API call to Blockchain takes less than half a second for a balance request. Is there a way for me to do that?
Those API services have several large servers hosting their databases. Their databases are massive and index everything in the blockchain. They store information like the balance of each address (which is technically not in the blockchain) so when you ask for the information, it is pulled from the database very quickly. Bitcoin Core does not do this as such databases are a waste of space and most users will not be affected by the slower functionality.