Skip to content

Commit

Permalink
Merge pull request #492 from evoskuil/master
Browse files Browse the repository at this point in the history
Optimization comments, move stream.set_limit() to debug.
  • Loading branch information
evoskuil authored Jun 13, 2024
2 parents 9f2049d + ec0b5d0 commit b2a79b4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/bitcoin/database/impl/primitives/arraymap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ bool CLASS::put_link(Link& link, const Element& element) NOEXCEPT

iostream stream{ *ptr };
flipper sink{ stream };
if constexpr (!is_slab) { sink.set_limit(Size * count); }
if constexpr (!is_slab) { BC_DEBUG_ONLY(sink.set_limit(Size * count);) }
return element.to_data(sink);
}

Expand Down
4 changes: 3 additions & 1 deletion include/bitcoin/database/impl/primitives/hashmap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Link CLASS::first(const Key& key) const NOEXCEPT
TEMPLATE
typename CLASS::iterator CLASS::it(const Key& key) const NOEXCEPT
{
// (14.09% + 5.36%)
// Expensive construction, avoid unless iteration is necessary.
return { manager_.get(), head_.top(key), key };
}
Expand Down Expand Up @@ -270,7 +271,8 @@ bool CLASS::put_link(Link& link, const Key& key,
return head_.push(link, next, index);
});

if constexpr (!is_slab) { sink.set_limit(Size * count); }
// (1.63%)
if constexpr (!is_slab) { BC_DEBUG_ONLY(sink.set_limit(Size * count);) }
return element.to_data(sink) && sink.finalize();
}

Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/database/impl/query/confirm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,15 @@ bool CLASS::is_strong(const header_link& link) const NOEXCEPT
TEMPLATE
bool CLASS::set_strong(const header_link& link) NOEXCEPT
{
// (0.22%) after milestone.
const auto txs = to_transactions(link);
if (txs.empty())
return false;

// ========================================================================
const auto scope = store_.get_transactor();

// (4.04%) after milestone.
// Clean allocation failure (e.g. disk full), see set_strong() comments.
return set_strong(link, txs, true);
// ========================================================================
Expand Down
13 changes: 3 additions & 10 deletions include/bitcoin/database/impl/query/translate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,8 @@ header_link CLASS::to_parent(const header_link& link) const NOEXCEPT
TEMPLATE
header_link CLASS::to_block(const tx_link& link) const NOEXCEPT
{
// (10.99%) from block_confirmable->unspendable_prevout->to_strong->to_block.

// (8.25%)
////const auto to_strong_tx_link = store_.strong_tx.first(link);

// (2.68%)
// (10.36%)
table::strong_tx::record strong{};
////if (!store_.strong_tx.get(to_strong_tx_link, strong))
if (!store_.strong_tx.find(link, strong))
return {};

Expand Down Expand Up @@ -404,7 +398,8 @@ spend_links CLASS::to_spenders(const foreign_point& point) const NOEXCEPT
// Iterate transactions that spend the point, saving each spender.
spend_links spenders{};
do
{ // BUGBUG: Deadlock due to holding iterator while querying own table.
{
// BUGBUG: Deadlock due to holding iterator while querying own table.
// TODO: refactor to make safe and also pass boolean result code.
spenders.push_back(to_spender(to_spend_tx(it.self()), point));
}
Expand Down Expand Up @@ -477,7 +472,6 @@ TEMPLATE
tx_links CLASS::to_transactions(const header_link& link) const NOEXCEPT
{
table::txs::slab txs{};
////if (!store_.txs.get(to_txs(link), txs))
if (!store_.txs.find(link, txs))
return {};

Expand All @@ -488,7 +482,6 @@ TEMPLATE
tx_link CLASS::to_coinbase(const header_link& link) const NOEXCEPT
{
table::txs::get_coinbase txs{};
////if (!store_.txs.get(to_txs(link), txs))
if (!store_.txs.find(link, txs))
return {};

Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/database/impl/query/validate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ bool CLASS::get_bits(uint32_t& bits, const header_link& link) const NOEXCEPT
TEMPLATE
bool CLASS::get_context(context& ctx, const header_link& link) const NOEXCEPT
{
// (4.04%)
table::header::record_context header{};
if (!store_.header.get(link, header))
return false;
Expand Down
8 changes: 8 additions & 0 deletions include/bitcoin/database/tables/schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ namespace schema
schema::put;
static constexpr size_t minrow = minsize;
static constexpr size_t size = max_size_t;
static inline linkage<pk> count() NOEXCEPT;
static_assert(minsize == 9u);
static_assert(minrow == 9u);
};
Expand Down Expand Up @@ -199,6 +200,7 @@ namespace schema
1u; // variable_size (minimum 1, average 1)
static constexpr size_t minrow = minsize;
static constexpr size_t size = max_size_t;
static inline linkage<pk> count() NOEXCEPT;
static_assert(minsize == 2u);
static_assert(minrow == 2u);
};
Expand All @@ -214,6 +216,7 @@ namespace schema
1u; // variable_size (minimum 1, average 1)
static constexpr size_t minrow = minsize;
static constexpr size_t size = max_size_t;
static inline linkage<pk> count() NOEXCEPT;
static_assert(minsize == 10u);
static_assert(minrow == 10u);
};
Expand Down Expand Up @@ -262,6 +265,7 @@ namespace schema
transaction::pk; // coinbase
static constexpr size_t minrow = pk + sk + minsize;
static constexpr size_t size = max_size_t;
static inline linkage<pk> count() NOEXCEPT;
static_assert(minsize == 11u);
static_assert(minrow == 19u);
};
Expand Down Expand Up @@ -328,6 +332,7 @@ namespace schema
one;
static constexpr size_t minrow = pk + sk + minsize;
static constexpr size_t size = max_size_t;
static inline linkage<pk> count() NOEXCEPT;
static_assert(minsize == 2u);
static_assert(minrow == 8u);
};
Expand All @@ -347,6 +352,7 @@ namespace schema
one;
static constexpr size_t minrow = pk + sk + minsize;
static constexpr size_t size = max_size_t;
static inline linkage<pk> count() NOEXCEPT;
static_assert(minsize == 14u);
static_assert(minrow == 23u);
};
Expand All @@ -362,6 +368,7 @@ namespace schema
one;
static constexpr size_t minrow = pk + sk + minsize;
static constexpr size_t size = max_size_t;
static inline linkage<pk> count() NOEXCEPT;
static_assert(minsize == 33u);
static_assert(minrow == 41u);
};
Expand All @@ -388,6 +395,7 @@ namespace schema
//// static constexpr size_t minsize = zero;
//// static constexpr size_t minrow = pk + sk + minsize;
//// static constexpr size_t size = max_size_t;
//// static inline linkage<pk> count() NOEXCEPT;
//// static_assert(minsize == 0u);
//// static_assert(minrow == 9u);
////};
Expand Down

0 comments on commit b2a79b4

Please sign in to comment.