From 09afe355d611e4841b400fd5ce6fddc928eaa807 Mon Sep 17 00:00:00 2001 From: Vincenzo Eduardo Padulano Date: Fri, 3 Oct 2025 17:40:22 +0200 Subject: [PATCH] [df] Change default Snapshot compression settings The default Snapshot compression setting has always been 101. Historically, this was done for simplicity reasons and following the principle of least surprise. TTree was the only output format available with Snapshot, so the operation was defaulting to the same value used by TTree. Now that Snapshot supports more than one output format, this reason is less strong than before. It has been established that 505 is a better default compression setting overall, so RDataFrame should follow that. The main disadvantage is that this change is hard to communicate. This commit proposes to introduce an information message being shown once per program execution, and only if the program is calling Snapshot. This message is supposed to help the users detect changes in their output file size with the next development cycle (6.38.x) and should be removed afterwards. --- README/ReleaseNotes/v638/index.md | 3 +++ tree/dataframe/inc/ROOT/RDF/RInterface.hxx | 21 ++++++++++++++++++++ tree/dataframe/inc/ROOT/RSnapshotOptions.hxx | 4 ++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README/ReleaseNotes/v638/index.md b/README/ReleaseNotes/v638/index.md index d391c89d78102..c5df528e21afe 100644 --- a/README/ReleaseNotes/v638/index.md +++ b/README/ReleaseNotes/v638/index.md @@ -115,7 +115,10 @@ If you want to keep using `TList*` return values, you can write a small adapter RDF uses one copy of each histogram per thread. Now, RDataFrame can reduce the number of clones using `ROOT::RDF::Experimental::ThreadsPerTH3()`. Setting this to numbers such as 8 would share one 3-d histogram among 8 threads, greatly reducing the memory consumption. This might slow down execution if the histograms are filled at very high rates. Use lower number in this case. + +### Snapshot - The Snapshot method has been refactored so that it does not need anymore compile-time information (i.e. either template arguments or JIT-ting) to know the input column types. This means that any Snapshot call that specifies the template arguments, e.g. `Snapshot(..., {"intCol", "floatCol"})` is now redundant and the template arguments can safely be removed from the call. At the same time, Snapshot does not need to JIT compile the column types, practically giving huge speedups depending on the number of columns that need to be written to disk. In certain cases (e.g. when writing O(10000) columns) the speedup can be larger than an order of magnitude. The Snapshot template is now deprecated and it will issue a compile-time warning when called. The function overload is scheduled for removal in ROOT 6.40. +- The default compression setting for the output dataset used by Snapshot has been changed from 101 (ZLIB level 1, the TTree default) to 505 (ZSTD level 5). This is a better setting on average, and makes more sense for RDataFrame since now the Snapshot operation supports more than just the TTree output data format. This change may result in smaller output file sizes for your analyses that use Snapshot with default settings. During the 6.38 development release cycle, Snapshot will print information about this change once per program run. Starting from 6.40.00, the information will not be printed. The message can be suppressed by setting ROOT_RDF_SILENCE_SNAPSHOT_INFO=1 in your environment. ## Python Interface diff --git a/tree/dataframe/inc/ROOT/RDF/RInterface.hxx b/tree/dataframe/inc/ROOT/RDF/RInterface.hxx index 8153f6dee9ded..3a749dfb75a18 100644 --- a/tree/dataframe/inc/ROOT/RDF/RInterface.hxx +++ b/tree/dataframe/inc/ROOT/RDF/RInterface.hxx @@ -32,6 +32,7 @@ #include "ROOT/RResultPtr.hxx" #include "ROOT/RSnapshotOptions.hxx" #include +#include "ROOT/RLogger.hxx" #include "ROOT/RVec.hxx" #include "ROOT/TypeTraits.hxx" #include "RtypesCore.h" // for ULong64_t @@ -44,8 +45,12 @@ #include "TProfile2D.h" #include "TStatistic.h" +#include "ROOT/RVersion.hxx" + #include #include +#include +#include #include #include // std::back_insterter #include @@ -1331,6 +1336,22 @@ public: const ColumnNames_t &columnList, const RSnapshotOptions &options = RSnapshotOptions()) { + // TODO: Remove before releasing 6.40.00 +#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 40, 0) + static_assert(false && "Remove information about change of Snapshot defaut compression settings."); +#endif + [[maybe_unused]] static bool once = []() { + if (const char *suppress = std::getenv("ROOT_RDF_SILENCE_SNAPSHOT_INFO")) + if (std::strcmp(suppress, "1") == 0) + return true; + RLogScopedVerbosity showInfo{ROOT::Detail::RDF::RDFLogChannel(), ROOT::ELogLevel::kInfo}; + R__LOG_INFO(ROOT::Detail::RDF::RDFLogChannel()) + << "In ROOT 6.38, the default compression settings of Snapshot have been changed from 101 (ZLIB with " + "compression level 1, the TTree default) to 505 (ZSTD with compression level 5). This change may result " + "in smaller Snapshot output dataset size by default. In order to suppress this message, set " + "ROOT_RDF_SILENCE_SNAPSHOT_INFO=1 in your environment."; + return true; + }(); // like columnList but with `#var` columns removed auto colListNoPoundSizes = RDFInternal::FilterArraySizeColNames(columnList, "Snapshot"); // like columnListWithoutSizeColumns but with aliases resolved diff --git a/tree/dataframe/inc/ROOT/RSnapshotOptions.hxx b/tree/dataframe/inc/ROOT/RSnapshotOptions.hxx index 6d558d2188e46..2ddd0e7381602 100644 --- a/tree/dataframe/inc/ROOT/RSnapshotOptions.hxx +++ b/tree/dataframe/inc/ROOT/RSnapshotOptions.hxx @@ -46,8 +46,8 @@ struct RSnapshotOptions { } std::string fMode = "RECREATE"; ///< Mode of creation of output file ECAlgo fCompressionAlgorithm = - ROOT::RCompressionSetting::EAlgorithm::kZLIB; ///< Compression algorithm of output file - int fCompressionLevel = 1; ///< Compression level of output file + ROOT::RCompressionSetting::EAlgorithm::kZSTD; ///< Compression algorithm of output file + int fCompressionLevel = 5; ///< Compression level of output file int fAutoFlush = 0; ///< AutoFlush value for output tree int fSplitLevel = 99; ///< Split level of output tree bool fLazy = false; ///< Do not start the event loop when Snapshot is called