Skip to content

Commit d24b813

Browse files
committed
Optional PMR (MSVC 5-10% performance gain in creation)
1 parent d135fd2 commit d24b813

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ What is Morton-Z space-filling curve? https://en.wikipedia.org/wiki/Z-order_curv
8282
* Boost: 2D, 3D; `boost::geometry::octree_point`, `octree_box`, etc. (adaptor.boost.h)
8383
* `struct{x,y,z}`: 2D, 3D; (adaptor.xyz.h)
8484

85+
## Optional defines
86+
The following defines can be used before the header file include:
87+
* `ORTHOTREE__USE_PMR` / `ORTHOTREE__DISABLE_PMR`: polymorphic allocators can be used in the node container. On MSVC it could have significant performance gain (5-10%). Therefore, on MSVC the default is `ON`, but it is overridable with these flags.
88+
* `ORTHOTREE__DISABLED_NODECENTER`: It turns off node center calculation during creation. Less memory is used, but in specific algorithms it must be calculated repeatedly.
89+
* `ORTHOTREE__DISABLED_NODESIZE`: It turns off the node size calculation during initialization. Otherwise node sizes are contained level-wise.
90+
8591
## Major aliases in OrthoTree
8692
```C++
8793
/// Default geometrical base elements

octree.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,19 @@ Node center is not stored within the nodes. It will be calculated ad-hoc everyti
3131
3232
Node size is not stored within the nodes. It will be calculated ad-hoc everytime when it is required, e.g in search algorithm.
3333
#define ORTHOTREE__DISABLED_NODESIZE
34+
35+
// PMR is used with MSVC only by default. To use PMR anyway
36+
ORTHOTREE__USE_PMR
37+
38+
// To disable PMR on all platforms use:
39+
ORTHOTREE__DISABLE_PMR
3440
*/
3541

42+
#if defined(ORTHOTREE__USE_PMR) || defined(_MSC_VER)
43+
#ifndef ORTHOTREE__DISABLE_PMR
44+
#define IS_PMR_USED
45+
#endif // !ORTHOTREE__DISABLE_PMR
46+
#endif
3647

3748
#ifndef ORTHOTREE_GUARD
3849
#define ORTHOTREE_GUARD
@@ -2036,19 +2047,30 @@ namespace OrthoTree
20362047
Node const* NodePtr;
20372048
};
20382049

2039-
2050+
#ifdef IS_PMR_USED
20402051
template<typename TData>
20412052
using LinearUnderlyingContainer = std::pmr::unordered_map<MortonNodeID, TData>;
20422053

20432054
template<typename TData>
20442055
using NonLinearUnderlyingContainer = std::pmr::map<MortonNodeID, TData, bitset_arithmetic_compare>;
2056+
#else
2057+
template<typename TData>
2058+
using LinearUnderlyingContainer = std::unordered_map<MortonNodeID, TData>;
2059+
2060+
template<typename TData>
2061+
using NonLinearUnderlyingContainer = std::map<MortonNodeID, TData, bitset_arithmetic_compare>;
2062+
#endif // IS_PMR_USED
20452063

20462064
template<typename TData>
20472065
using UnderlyingContainer = typename std::conditional_t<SI::IS_LINEAR_TREE, LinearUnderlyingContainer<TData>, NonLinearUnderlyingContainer<TData>>;
20482066

20492067
protected: // Member variables
2068+
#ifdef IS_PMR_USED
20502069
std::pmr::unsynchronized_pool_resource m_umrNodes;
20512070
UnderlyingContainer<Node> m_nodes = UnderlyingContainer<Node>(&m_umrNodes);
2071+
#else
2072+
UnderlyingContainer<Node> m_nodes;
2073+
#endif
20522074

20532075
std::size_t m_maxElementNo = 11;
20542076
depth_t m_maxDepthNo = {};
@@ -2057,6 +2079,7 @@ namespace OrthoTree
20572079

20582080
detail::GridSpaceIndexing<DIMENSION_NO, TGeometry, TVector, TBox, AD> m_grid;
20592081

2082+
#ifdef IS_PMR_USED
20602083
protected: // Constructors
20612084
OrthoTreeBase() = default;
20622085

@@ -2082,7 +2105,7 @@ namespace OrthoTree
20822105
m_nodes = other.m_nodes;
20832106
return *this;
20842107
}
2085-
2108+
#endif // IS_PMR_USED
20862109

20872110
public: // Node helpers
20882111
// Get EntityIDs of the node

0 commit comments

Comments
 (0)