diff --git a/src/mongo/db/storage/wiredtiger/SConscript b/src/mongo/db/storage/wiredtiger/SConscript
index ea525c39228..9c02a8727be 100644
--- a/src/mongo/db/storage/wiredtiger/SConscript
+++ b/src/mongo/db/storage/wiredtiger/SConscript
@@ -31,6 +31,7 @@ wtEnv.Library(
         'oplog_truncate_markers_server_status_section.cpp',
         'wiredtiger_begin_transaction_block.cpp',
         'wiredtiger_column_store.cpp',
+        'wiredtiger_compiled_configuration.cpp',
         'wiredtiger_cursor.cpp',
         'wiredtiger_cursor_helpers.cpp',
         'wiredtiger_global_options.cpp',
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp
index 5b1448c30b8..c7ac0d9cd49 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.cpp
@@ -38,6 +38,7 @@
 #include "mongo/db/service_context.h"
 #include "mongo/db/storage/storage_parameters_gen.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.h"
+#include "mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
 #include "mongo/platform/compiler.h"
 #include "mongo/util/assert_util_core.h"
@@ -49,6 +50,9 @@
 namespace mongo {
 using namespace fmt::literals;
 
+static CompiledConfiguration compiledBeginTransaction("WT_SESSION.begin_transaction",
+  "ignore_prepare=%s,roundup_timestamps=(prepared=%d,read=%d),no_timestamp=%d");
+
 WiredTigerBeginTxnBlock::WiredTigerBeginTxnBlock(
     WT_SESSION* session,
     PrepareConflictBehavior prepareConflictBehavior,
@@ -58,6 +62,7 @@ WiredTigerBeginTxnBlock::WiredTigerBeginTxnBlock(
     : _session(session) {
     invariant(!_rollback);
 
+#if 0
     str::stream builder;
     if (prepareConflictBehavior == PrepareConflictBehavior::kIgnoreConflicts) {
         builder << "ignore_prepare=true,";
@@ -89,6 +94,47 @@ WiredTigerBeginTxnBlock::WiredTigerBeginTxnBlock(
 
     const std::string beginTxnConfigString = builder;
     invariantWTOK(_session->begin_transaction(_session, beginTxnConfigString.c_str()), _session);
+
+#else
+    const char* ignore_prepare;
+    if (prepareConflictBehavior == PrepareConflictBehavior::kIgnoreConflicts) {
+        ignore_prepare = "true";
+    } else if (prepareConflictBehavior == PrepareConflictBehavior::kIgnoreConflictsAllowWrites) {
+        ignore_prepare = "force";
+    } else {
+        ignore_prepare = "false";
+    }
+
+    bool roundup_prepared = false;
+    bool roundup_read = false;
+    if (roundUpPreparedTimestamps == RoundUpPreparedTimestamps::kRound ||
+        roundUpReadTimestamp == RoundUpReadTimestamp::kRound) {
+        if (roundUpPreparedTimestamps == RoundUpPreparedTimestamps::kRound) {
+            roundup_prepared = true;
+        }
+        if (roundUpReadTimestamp == RoundUpReadTimestamp::kRound) {
+            roundup_read = true;
+        }
+    }
+
+    bool no_timestamp = false;
+    if (allowUntimestampedWrite != RecoveryUnit::UntimestampedWriteAssertionLevel::kEnforce) {
+        no_timestamp = true;
+    } else if (MONGO_unlikely(gAllowUnsafeUntimestampedWrites &&
+                              getReplSetMemberInStandaloneMode(getGlobalServiceContext()) &&
+                              !repl::ReplSettings::shouldRecoverFromOplogAsStandalone())) {
+        // We can safely ignore setting this configuration option when recovering from the oplog as
+        // standalone because:
+        // 1. Replaying oplog entries write with a timestamp.
+        // 2. The instance is put in read-only mode after oplog application has finished.
+        no_timestamp = true;
+    }
+
+    const char *compiledConfig = compiledBeginTransaction.getConfig(_session);
+    invariantWTOK(_session->bind_configuration(_session, compiledConfig,
+      ignore_prepare, (int)roundup_prepared, (int)roundup_read, (int)no_timestamp), _session);
+    invariantWTOK(_session->begin_transaction(_session, compiledConfig), _session);
+#endif
     _rollback = true;
 }
 
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.cpp
new file mode 100644
index 00000000000..ad5c3c38473
--- /dev/null
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.cpp
@@ -0,0 +1,78 @@
+/**
+ *    Copyright (C) 2024-present MongoDB, Inc.
+ *
+ *    This program is free software: you can redistribute it and/or modify
+ *    it under the terms of the Server Side Public License, version 1,
+ *    as published by MongoDB, Inc.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    Server Side Public License for more details.
+ *
+ *    You should have received a copy of the Server Side Public License
+ *    along with this program. If not, see
+ *    <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ *    As a special exception, the copyright holders give permission to link the
+ *    code of portions of this program with the OpenSSL library under certain
+ *    conditions as described in each individual source file and distribute
+ *    linked combinations including the program with the OpenSSL library. You
+ *    must comply with the Server Side Public License in all respects for
+ *    all of the code used other than as permitted herein. If you modify file(s)
+ *    with this exception, you may extend this exception to your version of the
+ *    file(s), but you are not obligated to do so. If you do not wish to do so,
+ *    delete this exception statement from your version. If you delete this
+ *    exception statement from all source files in the program, then also delete
+ *    it in the license file.
+ */
+
+#include "mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.h"
+#include "mongo/db/storage/wiredtiger/wiredtiger_session_data.h"
+
+namespace mongo {
+
+CompiledConfiguration::CompiledConfiguration(const char *apiName, const char *config)
+    : _apiName(apiName), _config(config)
+{
+    CompiledConfigurationRegistry::instance()->add(apiName, config);
+}
+
+const char *CompiledConfiguration::getConfig(WT_SESSION *session)
+{
+    SessionData* data = SessionData::get(session);
+    CompiledConfigurationsPerConnection* compiled = data->getCompiledConfigurationsPerConnection();
+    return (compiled->get(_compileToken));
+}
+
+// -----------------------
+
+
+Status CompiledConfigurationsPerConnection::compileAll(WT_CONNECTION *conn)
+{
+    auto registry = CompiledConfigurationRegistry::instance();
+    _compileResults.clear();
+    for (int i = 0; i < registry->size(); ++i) {
+        auto compile_pair = registry->get(i);
+        const char *compiled;
+        int ret = conn->compile_configuration(conn, compile_pair.first.c_str(), compile_pair.second.c_str(), &compiled);
+        if (ret != 0) {
+            StringBuilder msg;
+            msg << "WiredTiger configuration compilation failed: \"" << compile_pair.first
+                << "\", \"" << compile_pair.second << "\"";
+            return Status(ErrorCodes::UnknownError, msg.str());
+        }
+        _compileResults.push_back(compiled);
+    }
+    return Status::OK();
+}
+
+// -----------------------
+
+int CompiledConfigurationRegistry::add(const char *apiName, const char *config) {
+    int compileToken = _configs.size();
+    _configs.push_back(CompileSpec(apiName, config));
+    return compileToken;
+}
+
+}  // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.h b/src/mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.h
new file mode 100644
index 00000000000..a62383f5699
--- /dev/null
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.h
@@ -0,0 +1,99 @@
+/**
+ *    Copyright (C) 2024-present MongoDB, Inc.
+ *
+ *    This program is free software: you can redistribute it and/or modify
+ *    it under the terms of the Server Side Public License, version 1,
+ *    as published by MongoDB, Inc.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    Server Side Public License for more details.
+ *
+ *    You should have received a copy of the Server Side Public License
+ *    along with this program. If not, see
+ *    <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ *    As a special exception, the copyright holders give permission to link the
+ *    code of portions of this program with the OpenSSL library under certain
+ *    conditions as described in each individual source file and distribute
+ *    linked combinations including the program with the OpenSSL library. You
+ *    must comply with the Server Side Public License in all respects for
+ *    all of the code used other than as permitted herein. If you modify file(s)
+ *    with this exception, you may extend this exception to your version of the
+ *    file(s), but you are not obligated to do so. If you do not wish to do so,
+ *    delete this exception statement from your version. If you delete this
+ *    exception statement from all source files in the program, then also delete
+ *    it in the license file.
+ */
+
+#pragma once
+
+#include <wiredtiger.h>
+#include "mongo/base/status.h"
+
+namespace mongo {
+
+/**
+ * A single compiled configuration.  An instance of this class can be declared statically
+ * near the point of use.
+ */
+class CompiledConfiguration {
+public:
+    CompiledConfiguration(const char *apiName, const char *config);
+
+    const char *getConfig(WT_SESSION *session);
+
+private:
+    std::string _apiName;
+    std::string _config;
+    int _compileToken;
+};
+
+/**
+ * All compiled configurations used for a single connection.
+ */
+class CompiledConfigurationsPerConnection {
+public:
+    CompiledConfigurationsPerConnection() {}
+
+    Status compileAll(WT_CONNECTION *conn);
+    const char *get(int compileToken) {
+        return _compileResults[compileToken];
+    }
+
+private:
+    // Cannot be std::string, as it is the address returned by the compile call that is important,
+    // any copying of the C string would not work.
+    std::vector<const char *> _compileResults;
+};
+
+/**
+ * Registry of configuration strings that are to be compiled.
+ */
+class CompiledConfigurationRegistry {
+public:
+    typedef std::pair<std::string, std::string> CompileSpec;
+
+    CompiledConfigurationRegistry() {}
+
+    int add(const char *apiName, const char *config);
+
+    int size() const {
+        return _configs.size();
+    }
+
+    CompileSpec get(int i) const {
+        return _configs[i];
+    }
+
+    static CompiledConfigurationRegistry *instance() {
+        static CompiledConfigurationRegistry _instance;
+        return &_instance;
+    }
+
+private:
+    std::vector<CompileSpec> _configs;
+};
+
+}  // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index_util.cpp
index 993947cba1a..6177d74ce0e 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_index_util.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index_util.cpp
@@ -112,7 +112,7 @@ Status WiredTigerIndexUtil::compact(Interruptible& interruptible,
 
         // Set a pointer on the WT_SESSION to the interruptible, so that WT::compact can use a
         // callback to check for interrupts.
-        SessionDataRAII sessionRaii(s, &interruptible);
+        SessionDataInterruptibleRAII sessionRaii(s, &interruptible);
 
         StringBuilder config;
         config << "timeout=0";
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index ba7974034fa..3dd907af4a8 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -657,6 +657,7 @@ void WiredTigerKVEngine::_openWiredTiger(const std::string& path, const std::str
 
     int ret = wiredtiger_open(path.c_str(), wtEventHandler, configStr.c_str(), &_conn);
     if (!ret) {
+        uassertStatusOK(_compiledConfigurations.compileAll(_conn));
         _fileVersion = {WiredTigerFileVersion::StartupVersion::IS_44_FCV_44};
         return;
     }
@@ -680,6 +681,7 @@ void WiredTigerKVEngine::_openWiredTiger(const std::string& path, const std::str
     configStr = wtOpenConfig + ",compatibility=(require_min=\"3.3.0\")";
     ret = wiredtiger_open(path.c_str(), wtEventHandler, configStr.c_str(), &_conn);
     if (!ret) {
+        uassertStatusOK(_compiledConfigurations.compileAll(_conn));
         _fileVersion = {WiredTigerFileVersion::StartupVersion::IS_44_FCV_42};
         return;
     }
@@ -688,6 +690,7 @@ void WiredTigerKVEngine::_openWiredTiger(const std::string& path, const std::str
     configStr = wtOpenConfig + ",compatibility=(require_min=\"3.2.0\")";
     ret = wiredtiger_open(path.c_str(), wtEventHandler, configStr.c_str(), &_conn);
     if (!ret) {
+        uassertStatusOK(_compiledConfigurations.compileAll(_conn));
         _fileVersion = {WiredTigerFileVersion::StartupVersion::IS_42};
         return;
     }
@@ -718,6 +721,7 @@ void WiredTigerKVEngine::_openWiredTiger(const std::string& path, const std::str
     if (!ret) {
         StorageRepairObserver::get(getGlobalServiceContext())
             ->invalidatingModification("WiredTiger metadata salvaged");
+        uassertStatusOK(_compiledConfigurations.compileAll(_conn));
         return;
     }
 
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
index 5958283c568..f9776d55a45 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
@@ -67,6 +67,7 @@
 #include "mongo/db/storage/snapshot_manager.h"
 #include "mongo/db/storage/sorted_data_interface.h"
 #include "mongo/db/storage/storage_engine.h"
+#include "mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_size_storer.h"
@@ -429,6 +430,10 @@ public:
     Status autoCompact(OperationContext* opCtx,
                        const StorageEngine::AutoCompactOptions& options) override;
 
+    CompiledConfigurationsPerConnection* getCompiledConfigurations() {
+        return &_compiledConfigurations;
+    }
+
 private:
     StatusWith<Timestamp> _pinOldestTimestamp(WithLock,
                                               const std::string& requestingServiceName,
@@ -601,5 +606,7 @@ private:
     // This is valid because durability is a state all operations will converge to eventually.
     AtomicWord<std::uint64_t> _currentCheckpointIteration{0};
     AtomicWord<std::uint64_t> _finishedCheckpointIteration{0};
+
+    CompiledConfigurationsPerConnection _compiledConfigurations;
 };
 }  // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index abc535ebe54..95ff2366431 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -1582,7 +1582,7 @@ Status WiredTigerRecordStore::doCompact(OperationContext* opCtx,
 
         // Set a pointer on the WT_SESSION to the opCtx, so that WT::compact can use a callback to
         // check for interrupts.
-        SessionDataRAII sessionRaii(s, opCtx);
+        SessionDataInterruptibleRAII sessionRaii(s, opCtx);
 
         std::string config = "timeout=0";
         if (freeSpaceTargetMB) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp
index f4149928b07..0c3a4479520 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp
@@ -45,6 +45,7 @@
 #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_parameters_gen.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
+#include "mongo/db/storage/wiredtiger/wiredtiger_session_data.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
 #include "mongo/logv2/log.h"
 #include "mongo/logv2/log_attr.h"
@@ -65,6 +66,7 @@ WiredTigerSession::WiredTigerSession(WT_CONNECTION* conn, uint64_t epoch, uint64
       _cursorsOut(0),
       _idleExpireTime(Date_t::min()) {
     invariantWTOK(conn->open_session(conn, nullptr, "isolation=snapshot", &_session), nullptr);
+    SessionData::allocate(_session);
 }
 
 WiredTigerSession::WiredTigerSession(WT_CONNECTION* conn,
@@ -78,10 +80,13 @@ WiredTigerSession::WiredTigerSession(WT_CONNECTION* conn,
       _cursorsOut(0),
       _idleExpireTime(Date_t::min()) {
     invariantWTOK(conn->open_session(conn, nullptr, "isolation=snapshot", &_session), nullptr);
+    SessionData *data = SessionData::allocate(_session);
+    data->setCompiledConfigurationsPerConnection(cache->getKVEngine()->getCompiledConfigurations());
 }
 
 WiredTigerSession::~WiredTigerSession() {
     if (_session) {
+        SessionData::deallocate(_session);
         invariantWTOK(_session->close(_session, nullptr), nullptr);
     }
 }
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_data.h b/src/mongo/db/storage/wiredtiger/wiredtiger_session_data.h
index 629811fd6d1..299b57cf427 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_data.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_data.h
@@ -32,29 +32,88 @@
 #include <wiredtiger.h>
 
 #include "mongo/util/interruptible.h"
+#include "mongo/db/storage/wiredtiger/wiredtiger_compiled_configuration.h"
 
 namespace mongo {
 
+/**
+ * Encapsulates private data held in a WT_SESSION.
+ */
+class SessionData {
+public:
+    SessionData() : _interruptible(nullptr), _compiled(nullptr) {}
+
+    /**
+     * Called to allocate the session data for the first time
+     * and attach it to the WT session.
+     */
+    static SessionData* allocate(WT_SESSION* session) {
+        invariant(session->app_private == nullptr);
+        SessionData* data = new SessionData();
+        session->app_private = data;
+        return data;
+    }
+
+    /**
+     * Called to deallocate the session data from the WT session.
+     */
+    static void deallocate(WT_SESSION* session) {
+        invariant(session->app_private != nullptr);
+        delete reinterpret_cast<SessionData*>(session->app_private);
+        session->app_private = nullptr;
+    }
+
+    /**
+     * Get the session data from the WT session.
+     */
+    static SessionData* get(WT_SESSION* session) {
+        invariant(session->app_private != nullptr);
+        return reinterpret_cast<SessionData*>(session->app_private);
+    }
+
+    void setInterruptible(Interruptible* interruptible) {
+        _interruptible = interruptible;
+    }
+
+    Interruptible* getInterruptible() {
+        return _interruptible;
+    }
+
+    void setCompiledConfigurationsPerConnection(CompiledConfigurationsPerConnection* compiled) {
+        _compiled = compiled;
+    }
+
+    CompiledConfigurationsPerConnection* getCompiledConfigurationsPerConnection() {
+        return _compiled;
+    }
+
+private:
+    Interruptible* _interruptible;
+    CompiledConfigurationsPerConnection* _compiled;
+};
+
 /**
  * Sets up a WT_SESSION to have callback data with which to check for MDB layer interrupts.
  * See the 'general_handle' callback defined for wiredtiger_open() for more details.
  */
-class SessionDataRAII {
+class SessionDataInterruptibleRAII {
 public:
     /**
      * Allows WT operations running on this 'session' access to the MDB layer 'interruptible'.
      */
-    SessionDataRAII(WT_SESSION* session, Interruptible* interruptible) : _session(session) {
-        invariant(!_session->app_private);
-        _session->app_private = interruptible;
+    SessionDataInterruptibleRAII(WT_SESSION* session, Interruptible* interruptible) : _session(session) {
+        SessionData* data = SessionData::get(_session);
+        invariant(!data->getInterruptible());
+        data->setInterruptible(interruptible);
     }
 
     /**
-     * Clears on exit the WT_SESSION::app_private void*. This allows the WT_SESSION to be safely
+     * Clears on exit the reference to the interruptibleWT_SESSION::app_private void*. This allows the WT_SESSION to be safely
      * returned to the WiredTigerSessionCache.
      */
-    ~SessionDataRAII() {
-        _session->app_private = nullptr;
+    ~SessionDataInterruptibleRAII() {
+        SessionData* data = SessionData::get(_session);
+        data->setInterruptible(nullptr);
     }
 
 private:
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
index d7a7b952b7a..c5099a0ff53 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
@@ -70,6 +70,7 @@
 #include "mongo/db/storage/wiredtiger/wiredtiger_parameters_gen.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h"
 #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
+#include "mongo/db/storage/wiredtiger/wiredtiger_session_data.h"
 #include "mongo/logv2/log.h"
 #include "mongo/logv2/redaction.h"
 #include "mongo/platform/atomic_word.h"
@@ -834,11 +835,16 @@ int mdb_handle_general(WT_EVENT_HANDLER* handler,
                        WT_SESSION* session,
                        WT_EVENT_TYPE type,
                        void* arg) {
-    if (type != WT_EVENT_COMPACT_CHECK || session == nullptr || session->app_private == nullptr) {
+    if (type != WT_EVENT_COMPACT_CHECK || session == nullptr) {
+        return 0;
+    }
+    SessionData *data = SessionData::get(session);
+    Interruptible *interruptible = data->getInterruptible();
+    if (interruptible == nullptr) {
         return 0;
     }
 
-    return reinterpret_cast<Interruptible*>(session->app_private)
+    return interruptible
                ->checkForInterruptNoAssert()
                .isOK()
         ? 0
