summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2024-03-24 21:31:38 +0000
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-04-15 16:15:27 +0200
commit82d3b20a9404c076ea6b1aa5cb1901c006569ae0 (patch)
tree4d7e17997dbe9e558fd10ebd580f9175bfd905fb /sc
parent774c1ddfecc6389234f8d0e68d6e17c1fe218cb1 (diff)
Related: tdf#160056 elide ref counting for initial tokens
The initial tokens provided to interpreting will be restored to their original ref count when interpreting is complete. So we could elide expensive ref counting for them for the duration of the the threaded group calculation. Possibly "temp" tokens that are created just during interpreting could additionally use thread-unsafe ref counts presuming they only appear in a thread specific context. Change-Id: I1f5b0198e83027781be15812680079f28b6a4e27 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165259 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> (cherry picked from commit 791a2489eecc3e59d7a31a4bb9e513a576db08ee) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165943 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/data/formulacell.cxx14
-rw-r--r--sc/source/core/inc/interpre.hxx3
-rw-r--r--sc/source/core/tool/interpr4.cxx9
3 files changed, 24 insertions, 2 deletions
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 2f0cf6c6bec5..74f88d1c008b 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -5011,6 +5011,13 @@ bool ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope
ScMutationDisable aGuard(rDocument, ScMutationGuardFlags::CORE);
+ // Here we turn off ref-counting for the contents of pCode on the basis
+ // that pCode is not modified by interpreting and when interpreting is
+ // complete all token refcounts will be back to their initial ref count
+ FormulaToken** pArray = pCode->GetArray();
+ for (sal_uInt16 i = 0, n = pCode->GetLen(); i < n; ++i)
+ pArray[i]->SetRefCntPolicy(RefCntPolicy::None);
+
// Start nThreadCount new threads
std::shared_ptr<comphelper::ThreadTaskTag> aTag = comphelper::ThreadPool::createThreadTaskTag();
ScThreadedInterpreterContextGetterGuard aContextGetterGuard(nThreadCount, rDocument, pNonThreadedFormatter);
@@ -5032,6 +5039,13 @@ bool ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope
// if they don't get joined from elsewhere before (via ThreadPool::waitUntilDone).
rThreadPool.waitUntilDone(aTag, false);
+ // Drop any caches that reference Tokens before restoring ref counting policy
+ for (int i = 0; i < nThreadCount; ++i)
+ aInterpreters[i]->DropTokenCaches();
+
+ for (sal_uInt16 i = 0, n = pCode->GetLen(); i < n; ++i)
+ pArray[i]->SetRefCntPolicy(RefCntPolicy::ThreadSafe);
+
rDocument.SetThreadedGroupCalcInProgress(false);
for (int i = 0; i < nThreadCount; ++i)
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index e0d7508fd581..6a74c4974112 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -1092,6 +1092,9 @@ public:
// Resets the interpreter object, allowing reuse of interpreter object for each cell
// in the group.
void Init( ScFormulaCell* pCell, const ScAddress& rPos, ScTokenArray& rTokArray );
+ // Used only for threaded formula-groups.
+ // Drops any caches that contain Tokens
+ void DropTokenCaches();
formula::StackVar Interpret();
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index c5a4ccfa9074..8764a7674a85 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -3888,9 +3888,8 @@ void ScInterpreter::Init( ScFormulaCell* pCell, const ScAddress& rPos, ScTokenAr
aCode.ReInit(rTokArray);
aPos = rPos;
pArr = &rTokArray;
- xResult = nullptr;
pJumpMatrix = nullptr;
- maTokenMatrixMap.clear();
+ DropTokenCaches();
pMyFormulaCell = pCell;
pCur = nullptr;
nGlobalError = FormulaError::NONE;
@@ -3907,6 +3906,12 @@ void ScInterpreter::Init( ScFormulaCell* pCell, const ScAddress& rPos, ScTokenAr
cPar = 0;
}
+void ScInterpreter::DropTokenCaches()
+{
+ xResult = nullptr;
+ maTokenMatrixMap.clear();
+}
+
ScCalcConfig& ScInterpreter::GetOrCreateGlobalConfig()
{
if (!mpGlobalConfig)