Commit da71dc6f37c69bdf708f1f9876e63ff348ae2296
1 parent
32e30a3a
QTC: cache get_env results for improved performance
It turns out that QUtil::get_env is particularly expensive on Windows if there is a large environment. This may be true on other platforms as well.
Showing
2 changed files
with
12 additions
and
2 deletions
TODO
| ... | ... | @@ -10,6 +10,8 @@ Before Release: |
| 10 | 10 | * Cache environment variables |
| 11 | 11 | * Remove coverage cases for things that are heavily exercised or are |
| 12 | 12 | in critical paths |
| 13 | +* Make ./performance_check usable by other people by having published | |
| 14 | + files to use for testing. | |
| 13 | 15 | * Evaluate issues tagged with `next` |
| 14 | 16 | * Stay on top of https://github.com/pikepdf/pikepdf/pull/315 |
| 15 | 17 | ... | ... |
libqpdf/QTC.cc
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | #include <qpdf/QUtil.hh> |
| 4 | 4 | #include <set> |
| 5 | +#include <map> | |
| 5 | 6 | #include <stdio.h> |
| 6 | 7 | |
| 7 | 8 | static bool |
| ... | ... | @@ -14,12 +15,19 @@ tc_active(char const* const scope) |
| 14 | 15 | void |
| 15 | 16 | QTC::TC(char const* const scope, char const* const ccase, int n) |
| 16 | 17 | { |
| 17 | - static std::set<std::pair<std::string, int>> cache; | |
| 18 | + static std::map<std::string, bool> active; | |
| 19 | + auto is_active = active.find(scope); | |
| 20 | + if (is_active == active.end()) { | |
| 21 | + active[scope] = tc_active(scope); | |
| 22 | + is_active = active.find(scope); | |
| 23 | + } | |
| 18 | 24 | |
| 19 | - if (!tc_active(scope)) { | |
| 25 | + if (!is_active->second) { | |
| 20 | 26 | return; |
| 21 | 27 | } |
| 22 | 28 | |
| 29 | + static std::set<std::pair<std::string, int>> cache; | |
| 30 | + | |
| 23 | 31 | std::string filename; |
| 24 | 32 | #ifdef _WIN32 |
| 25 | 33 | # define TC_ENV "TC_WIN_FILENAME" | ... | ... |