BUG: CreateStringArrayAction allocates every string during preflight
维护者通常 6 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- cpp
- 领域
- backend, performance, testing
调研方向
Read src/simplnx/Filter/Actions/CreateStringArrayAction.cpp and compare its mode handling with CreateArrayAction and CreateNeighborListAction; the issue identifies the unconditional value allocation as the problem. Check whether preflight code reads strings from arrays created by this action, then use the proposed test/EmptyStringStoreTest.cpp case to verify a preflight placeholder and add an execute mode check for initialized values. Done when both modes behave as expected and the focused test passes.
由索引模型根据 Issue 内容生成。
描述
Problem
CreateStringArrayAction ignores the action mode. In preflight it allocates one std::string for every tuple and creates a populated StringArray, instead of a placeholder store as CreateArrayAction and CreateNeighborListAction do. Preflight runs every time a parameter changes in the GUI, so a filter that creates a large string output allocates memory proportional to its tuple count on each preflight. An empty std::string takes about 24 bytes, so a 100 million tuple string array costs about 2.4 GB per preflight.
Expected: in IDataAction::Mode::Preflight the action creates the StringArray with an EmptyStringStore, which holds only the tuple shape. Actual: the array holds totalTuples real strings.
Seen on develop at 705a1b7f2. 22 filters use the action, for example Read CSV File, Read String Data Array, Concatenate Data Arrays and the EBSD readers.
Steps to Reproduce
- Configure simplnx with
SIMPLNX_BUILD_TESTS=ONat 705a1b7f2. - Add the test below to
test/EmptyStringStoreTest.cpp. - Build
simplnx_testand runctest --test-dir <build-dir> -R "CreateStringArrayAction" -j 1 --output-on-failure. - The test fails: the array created in preflight is not a placeholder.
Cause
CreateStringArrayAction::apply() receives mode but never reads it. It always builds the full value vector and a populated array (CreateStringArrayAction.cpp#L48-L51):
usize totalTuples = std::accumulate(m_Dims.cbegin(), m_Dims.cend(), static_cast<usize>(1), std::multiplies<>());
std::vector<std::string> values(totalTuples, m_InitializeValue);
StringArray* array = StringArray::CreateWithValues(dataStructure, name, m_Dims, values, dataObjectId);
The numeric path chooses a placeholder in preflight (ArrayCreationUtilities.hpp#L188), and pipeline preflight applies every action in that mode (PipelineFilter.cpp#L196).
Verification Unit Test
File: test/EmptyStringStoreTest.cpp. It also needs these includes:
#include "simplnx/DataStructure/DataStructure.hpp"
#include "simplnx/DataStructure/StringArray.hpp"
#include "simplnx/Filter/Actions/CreateStringArrayAction.hpp"
#include "simplnx/UnitTest/UnitTestCommon.hpp"
TEST_CASE("CreateStringArrayAction: preflight creates a placeholder store")
{
DataStructure dataStructure;
const DataPath arrayPath({"Strings"});
const CreateStringArrayAction action(ShapeType{1000}, arrayPath, "initial");
Result<> result = action.apply(dataStructure, IDataAction::Mode::Preflight);
SIMPLNX_RESULT_REQUIRE_VALID(result);
const auto* stringArray = dataStructure.getDataAs<StringArray>(arrayPath);
REQUIRE(stringArray != nullptr);
REQUIRE(stringArray->getNumberOfTuples() == 1000);
REQUIRE(stringArray->isPlaceholder());
}
Run only this test:
ctest --test-dir <build-dir> -R "CreateStringArrayAction" -j 1 --output-on-failure --timeout 1500 --no-tests=error
Failure seen on macOS arm64, Release build at 705a1b7f2:
test/EmptyStringStoreTest.cpp:78: FAILED:
REQUIRE( stringArray->isPlaceholder() )
with expansion:
false
test cases: 1 | 1 failed
assertions: 4 | 3 passed | 1 failed
Proposed Fix
In CreateStringArrayAction::apply(), branch on mode. For Mode::Preflight, create the array without values and give it an EmptyStringStore, as the metadata-only .dream3d import already does in Dream3dIO.cpp:
if(mode == Mode::Preflight)
{
StringArray* array = StringArray::CreateWithValues(dataStructure, name, m_Dims, {}, dataObjectId);
// ... same nullptr error handling as today
array->setStore(std::make_shared<EmptyStringStore>(m_Dims));
return {};
}
Keep the current code for Mode::Execute.
An EmptyStringStore throws on element access. Before the change, check that no preflightImpl() and no code that runs during pipeline preflight reads the values of a string array that an earlier filter created through this action, because those reads would start to throw. Add an execute-mode test that checks the array holds totalTuples copies of the initial value.
Notes
- Found while writing the simplnx style-guide rule "Preflight Does Not Allocate or Read Array Data" (PR #1889), which names this action as a current exception.
- Not verified: whether any filter reads string values during preflight today. The proposed-fix check above covers it.
- 主要语言
- C++
- 星标
- 18
- 派生
- 15
- 平均合并
- 4 天 23 小时
- 30 天内合并 PR
- 42
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
BlueQuartzSoftware/simplnx 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
BlueQuartzSoftware/simplnx#1987 ·
维护者通常 6 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 74/100
BlueQuartzSoftware/simplnx#1980 ·
维护者通常 6 天内回复
-
Testing
难度 2/5 1-3 小时 新手友好度 62/100
BlueQuartzSoftware/simplnx#1979 ·
维护者通常 6 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 65/100
BlueQuartzSoftware/simplnx#1978 ·
维护者通常 6 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
BlueQuartzSoftware/simplnx#1945 ·
维护者通常 6 天内回复
查看 BlueQuartzSoftware/simplnx 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
HarperFast/rocksdb-js#1118 ·
维护者通常 1 天内回复
-
bug triage
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
26.04 bug dark-mode Easy Hack impress symptom: visual
难度 2/5 1-3 小时 新手友好度 68/100
CollaboraOnline/online#16421 · 1 条评论 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 63/100
telegramdesktop/tdesktop#31653 ·
维护者通常 1 天内回复
-
area/cs bug
难度 2/5 1-3 小时 新手友好度 82/100
ydb-platform/ydb#59881 · 1 条评论 ·
维护者通常 1 天内回复