bitcoinerlab / descriptors

A TypeScript library for parsing Bitcoin Descriptors, including Miniscript-based ones. Streamlines creating Partially Signed Bitcoin Transactions (PSBTs) from Descriptors. Features BIP32, single-signature, and Hardware Wallet signing capabilities, and facilitates finalizing transactions.
https://bitcoinerlab.com/modules/descriptors
41 stars 14 forks source link

Forced to invoke the construtor and instantiate a new object every time I want to increment an address index #18

Closed serious-sammy closed 1 year ago

serious-sammy commented 1 year ago

Hello again! Another question:

Is it intended behavior that for every address index a new Descriptor object has to be instantiated with a new index option? Is there no way to increment an index of an already existing Descriptor instantiated from a ranged expression?

When creating a large amount of addresses (e.g. 2000+) it would likely yield much better performance to do something like .getAddress(index) on an existing instance. For example, in my current tx building implementation, new Descriptor() takes around 40% of the whole execution time - which is a noticeable hog when a large number of transactions, with multiple inputs each, needs to be generated, especially on lower-end devices.

Thanks again for this very useful library!

landabaso commented 1 year ago

Yes @serious-sammy that is correct. Descriptors are designed to be "per utxo", not using ranges. The whole API is around this concept.

Anyway, creating objects itself shouldn't pose a problem. Can you maybe benchmark and see which specific function calls are creating the bottleneck?