[libcxx-commits] [libcxx] [libc++] Add input validation for set_intersection() in debug mode. (PR #101508)
Konstantin Varlamov via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 12 16:28:15 PDT 2024
================
@@ -43,33 +43,31 @@
#include "test_iterators.h"
-namespace {
-
-// __debug_less will perform an additional comparison in an assertion
-static constexpr unsigned std_less_comparison_count_multiplier() noexcept {
-#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
- return 2;
+// Debug mode provides no complexity guarantees, testing them would be a waste of effort.
----------------
var-const wrote:
Thanks a lot for writing this out!
I think we've been somewhat consciously postponing making the decision on what kind of performance guarantees the debug mode should provide (if any) -- there was no pressing need to make a commitment there, and I wanted to gain some usage experience to inform this decision. I would say that from what I've seen so far, I'm leaning towards making the debug mode guarantee big-O complexity (the Standard sometimes mandates the exact number of operations which would be too strict, IMO). I'm very concerned that unless we keep even the debug mode relatively lightweight and performant, it will end up a mode that no one enables and thus is effectively useless; I'm especially concerned about a potential "death from a thousand cuts" scenario where many checks, each one not _that_ heavyweight on its own, add up to something that is unacceptably slow for too many users.
IIUC, the new checks don't really check the complexity here as well (it makes the average case worse, but worst case is the same).
We do need to test for the exact complexity in regular modes (since it's mandated by the Standard), but I can relate to your perspective that these tests aren't really well-suited for the debug mode. Not checking for complexity in the debug mode makes sense to me; we should change the comment, however, like Louis suggested.
https://github.com/llvm/llvm-project/pull/101508
More information about the libcxx-commits
mailing list