Chi check speedup - #177
Conversation
|
Related issue: #176 |
Moohan
left a comment
There was a problem hiding this comment.
Without really reading the C++ or knowing what the conventions are, I would say src/chi_check.cpp should be split into a few scripts, especially splitting the cpp_chi_check definition from the cpp_dob_from_chi definition.
| LazyData: true | ||
| LinkingTo: | ||
| cppally | ||
| SystemRequirements: C++20 |
There was a problem hiding this comment.
As far as I can tell C++20 became the default in 4.6.0 https://cran.r-project.org/doc/manuals/r-release/NEWS.html
What am I missing / what version of R would we need to allow as the minimum, ideally this would not be greater than the current PHS minimum of 4.4
There was a problem hiding this comment.
This is a good point and it doesn't look like there's a clear answer. The closest answer I can see is that C++20 can be specified from R 4.5.0 and (R 4.5.3 on Windows), according to Writing R Extensions, so that's probably the minimum reliable version unfortunately.
There was a problem hiding this comment.
{cpally} needs R 4.5, so that's also a floor for the dependency.
I think when PHS does the next upgrade, we'll still be keeping 4.4, so we really need to support that. Which means we either need a speed-up that works with at least 4.4, or cpally needs to be an optional dep and we have code that gates on the R version (and whether cpally is installed); we could remove the gating and 'upgrade' the dependency in the future when PHS stops supporting / providing the older R versions.
There was a problem hiding this comment.
Happy to go either way really.
cppally doesn't need to be installed thankfully - LinkingTo (cppally >= 1.1.0) just makes the header files of the package available.
We could gate on whether C++20 is available and if cppally headers are available, like:
#if __cplusplus >= 202002L && defined(CPPALLY_HPP)
#include <cppally.hpp>
// C++ 20 code
#else
# // C++ 17 code as it's the default anyway for R 4.4.0
#endif| Language: en-GB | ||
| LazyData: true | ||
| LinkingTo: | ||
| cppally |
There was a problem hiding this comment.
I think if we're introducing a C++ dependency I'd prefer it to be something more mainstream like {cpp11} unless there's a really solid reason not to, and in this case since the functions work fine in pure R, I'm not sure it would be worth it.
There was a problem hiding this comment.
It can be done but I believe it require a lot more code to achieve the same results for the following reasons.
As far as I know, cpp11 doesn't have a native r_date class, which is doing a lot of heavy-lifting of constructing dates from the DDMMYY part of chi numbers, thanks to the chrono library, which itself is a standard feature of C++20, so no extra dependencies to think about on that front.
A smaller but helpful feature is pmap() which helps reduce a lot of manual for-loops while also handling efficient recycling of elements.
There was a problem hiding this comment.
In terms of being worth it, I would argue that based on my benchmarks, it seems to offer a 20x improvement in speed, which is a clear benefit to anyone running chi checks on large numbers of chis.
Currently a work-in-progress.
This PR introduces a C++ re-write of both
chi_check()anddob_from_chi(), using the C++20 API R package cppally.