From a871ada2a942624e95abc7622f9bc0d3af1f1305 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 22 Jul 2021 23:06:00 +0200 Subject: GeoTIFF grid reading: perf improvements (fixes #2785) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this commit, and the 2 previous ones, given mytest.cpp ``` int main() { PJ* pj = proj_create(nullptr, "+proj=vgridshift +grids=us_nga_egm96_15.tif"); for( int i = 0; i < 5*1000*1000; i++) { PJ_COORD coord; coord.lpz.lam = 0; coord.lpz.phi = 0; coord.lpz.z = 0; proj_trans(pj, PJ_FWD, coord); } return 0; } ``` we get a x2 speedup Before: ``` $ PROJ_LIB=data:$HOME/proj/PROJ-data/us_nga LD_LIBRARY_PATH=src/.libs hyperfine --warmup 1 'taskset -c 11 ./mytest' Benchmark #1: taskset -c 11 ./mytest Time (mean ± σ): 1.950 s ± 0.014 s [User: 1.945 s, System: 0.005 s] Range (min … max): 1.937 s … 1.971 s ``` After: ``` $ PROJ_LIB=data:$HOME/proj/PROJ-data/us_nga LD_LIBRARY_PATH=src/.libs hyperfine --warmup 1 'taskset -c 11 ./mytest' Benchmark #1: taskset -c 11 ./mytest Time (mean ± σ): 984.4 ms ± 3.1 ms [User: 977.0 ms, System: 7.2 ms] Range (min … max): 979.3 ms … 990.5 ms ``` --- include/proj/internal/lru_cache.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include') diff --git a/include/proj/internal/lru_cache.hpp b/include/proj/internal/lru_cache.hpp index b7aff6b9..b2e997b3 100644 --- a/include/proj/internal/lru_cache.hpp +++ b/include/proj/internal/lru_cache.hpp @@ -160,6 +160,21 @@ class Cache { keys_.splice(keys_.begin(), keys_, iter->second); return iter->second->value; } + + /** + * The const reference returned here is only + * guaranteed to be valid till the next insert/delete + */ + const Value* getPtr(const Key& k) { + Guard g(lock_); + const auto iter = cache_.find(k); + if (iter == cache_.end()) { + return nullptr; + } + keys_.splice(keys_.begin(), keys_, iter->second); + return &(iter->second->value); + } + /** * returns a copy of the stored object (if found) */ -- cgit v1.2.3