mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Performance Improvement: Use a cache which caches result for getFacePositions.
This greatly reduce the number of std::list generated by caching the result, which is always constant for each radius selected. In the callgrind map, you will see original: * 3.3M calls to std::list for 9700 calls to getFacePositions In the modified version, you will see: * 3.3K calls to std::list for 6900 call to getFacePositions Callgrind map is here: #2321 it's a huge performance improvement to l_find_node_near
This commit is contained in:
parent
ed04e8e9e4
commit
7c8793cbea
4 changed files with 81 additions and 68 deletions
|
@ -25,10 +25,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "../irr_v3d.h"
|
||||
#include "../irr_aabb3d.h"
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
// Calculate the borders of a "d-radius" cube
|
||||
void getFacePositions(std::list<v3s16> &list, u16 d);
|
||||
|
||||
/*
|
||||
* This class permits to cache getFacePosition call results
|
||||
* This reduces CPU usage and vector calls
|
||||
*/
|
||||
class FacePositionCache
|
||||
{
|
||||
public:
|
||||
static std::vector<v3s16> getFacePositions(u16 d);
|
||||
private:
|
||||
static void generateFacePosition(u16 d);
|
||||
static std::map<u16, std::vector<v3s16> > m_cache;
|
||||
};
|
||||
|
||||
class IndentationRaiser
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue