Skip to content

Commit c732179

Browse files
committed
Improved performance of LeafNode ValueIters
Signed-off-by: Nick Avramoussis <[email protected]>
1 parent 28ccbc1 commit c732179

2 files changed

Lines changed: 30 additions & 16 deletions

File tree

openvdb/openvdb/tree/LeafNode.h

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,28 +222,36 @@ class LeafNode
222222
using BaseT = SparseIteratorBase<MaskIterT, ValueIter, NodeT, ValueT>;
223223

224224
ValueIter() {}
225-
ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
225+
ValueIter(const MaskIterT& iter, NodeT* parent)
226+
: BaseT(iter, parent)
227+
// Unlike other value iterators, cache the buffer data as part of
228+
// the iterators members to avoid the cost of going through the
229+
// leaf buffer atomic/checking API
230+
, mData(parent->buffer().data()) {}
226231

227-
ValueT& getItem(Index pos) const { return this->parent().getValue(pos); }
228-
ValueT& getValue() const { return this->parent().getValue(this->pos()); }
232+
ValueT& getItem(Index pos) const { return mData[pos]; }
233+
ValueT& getValue() const { return this->getItem(this->pos()); }
229234

230235
// Note: setItem() can't be called on const iterators.
231-
void setItem(Index pos, const ValueT& value) const
232-
{
233-
this->parent().setValueOnly(pos, value);
234-
}
236+
void setItem(Index pos, const ValueT& value) { mData[pos] = value; }
235237
// Note: setValue() can't be called on const iterators.
236-
void setValue(const ValueT& value) const
237-
{
238-
this->parent().setValueOnly(this->pos(), value);
239-
}
238+
void setValue(const ValueT& value) { this->setItem(this->pos(), value); }
240239

241240
// Note: modifyItem() can't be called on const iterators.
242241
template<typename ModifyOp>
243-
void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
242+
void modifyItem(Index n, const ModifyOp& op)
243+
{
244+
op(mData[n]);
245+
this->parent().setValueOn(n);
246+
}
244247
// Note: modifyValue() can't be called on const iterators.
245248
template<typename ModifyOp>
246-
void modifyValue(const ModifyOp& op) const { this->parent().modifyValue(this->pos(), op); }
249+
void modifyValue(const ModifyOp& op)
250+
{
251+
this->modifyItem(this->pos(), op);
252+
}
253+
private:
254+
ValueT* mData;
247255
};
248256

249257
/// Leaf nodes have no children, so their child iterators have no get/set accessors.
@@ -284,11 +292,11 @@ class LeafNode
284292
};
285293

286294
public:
287-
using ValueOnIter = ValueIter<MaskOnIterator, LeafNode, const ValueType, ValueOn>;
295+
using ValueOnIter = ValueIter<MaskOnIterator, LeafNode, ValueType, ValueOn>;
288296
using ValueOnCIter = ValueIter<MaskOnIterator, const LeafNode, const ValueType, ValueOn>;
289-
using ValueOffIter = ValueIter<MaskOffIterator, LeafNode, const ValueType, ValueOff>;
297+
using ValueOffIter = ValueIter<MaskOffIterator, LeafNode, ValueType, ValueOff>;
290298
using ValueOffCIter = ValueIter<MaskOffIterator,const LeafNode,const ValueType,ValueOff>;
291-
using ValueAllIter = ValueIter<MaskDenseIterator, LeafNode, const ValueType, ValueAll>;
299+
using ValueAllIter = ValueIter<MaskDenseIterator, LeafNode, ValueType, ValueAll>;
292300
using ValueAllCIter = ValueIter<MaskDenseIterator,const LeafNode,const ValueType,ValueAll>;
293301
using ChildOnIter = ChildIter<MaskOnIterator, LeafNode, ChildOn>;
294302
using ChildOnCIter = ChildIter<MaskOnIterator, const LeafNode, ChildOn>;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
OpenVDB:
2+
- Improvements:
3+
- Significantly improved the performance of all LeafNode ValueIterators,
4+
especially when delay loading is enabled. Construction of a ValueIterator
5+
on a leaf node now requests the leaf buffers ahead of iteration to avoid
6+
expensive API calls.

0 commit comments

Comments
 (0)