Skip to content

Commit 8e785cb

Browse files
committed
Improve build times with the http feature by 65% (!)
From around 6 minutes to 2 minutes. Accomplished by building a more balanced `Or` tree of warp filters. The tree being built is not optimally balanced, because the code also optimizes for readability. This could be further improved with a macro that creates the optimally balanced tree, which would be more easily maintainable and readable compared to hand-crafting it. Refs: #15, seanmonstar/warp#619
1 parent 1ac1059 commit 8e785cb

1 file changed

Lines changed: 25 additions & 30 deletions

File tree

src/http.rs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -429,36 +429,31 @@ async fn run(
429429
})
430430
.map(handle_error);
431431

432-
let handlers = hd_wallets_handler
433-
.or(hd_wallet_handler)
434-
.or(hd_key_handler) // needs to be before spk_handler to work fpr keys that don't have any indexed history
435-
.or(hd_gap_handler)
436-
.or(hd_next_handler)
437-
.or(spk_handler)
438-
.or(spk_utxo_handler)
439-
.or(spk_stats_handler)
440-
.or(spk_txs_handler)
441-
.or(spk_txs_compact_handler)
442-
.or(tx_handler)
443-
.or(tx_verbose_handler)
444-
.or(tx_hex_handler)
445-
.or(tx_proof_handler)
446-
.or(txs_since_handler)
447-
.or(txs_since_compact_handler)
448-
.or(tx_broadcast_handler)
449-
.or(txo_handler)
450-
.or(utxos_handler)
451-
.or(sse_handler)
452-
.or(spk_sse_handler)
453-
.or(block_tip_handler)
454-
.or(block_header_handler)
455-
.or(block_hex_handler)
456-
.or(block_height_handler)
457-
.or(mempool_histogram_handler)
458-
.or(fee_estimate_handler)
459-
.or(dump_handler)
460-
.or(debug_handler)
461-
.or(sync_handler)
432+
// hd_key_handler needs to be oredered before spk_handler, so it'll work with keys that don't have any indexed history
433+
434+
let hd_handlers = hd_wallets_handler
435+
.or(hd_wallet_handler.or(hd_key_handler))
436+
.or(hd_gap_handler.or(hd_next_handler));
437+
let spk_handlers = spk_handler
438+
.or(spk_utxo_handler.or(spk_stats_handler))
439+
.or(spk_txs_handler.or(spk_txs_compact_handler));
440+
let tx_handlers = tx_handler
441+
.or(tx_verbose_handler.or(tx_hex_handler))
442+
.or(tx_proof_handler.or(txs_since_handler))
443+
.or(txs_since_compact_handler.or(tx_broadcast_handler));
444+
let txo_handlers = txo_handler.or(utxos_handler);
445+
let sse_handlers = sse_handler.or(spk_sse_handler);
446+
let block_handlers = block_tip_handler
447+
.or(block_header_handler.or(block_hex_handler))
448+
.or(block_height_handler);
449+
let mempool_handlers = mempool_histogram_handler.or(fee_estimate_handler);
450+
let other_handlers = dump_handler.or(debug_handler.or(sync_handler));
451+
452+
let handlers = hd_handlers
453+
.or(spk_handlers.or(tx_handlers))
454+
.or(txo_handlers.or(sse_handlers))
455+
.or(block_handlers.or(mempool_handlers))
456+
.or(other_handlers)
462457
.or(warp::any().map(|| StatusCode::NOT_FOUND))
463458
.with(warp::log("bwt::http"))
464459
.with(warp::reply::with::headers(headers));

0 commit comments

Comments
 (0)