[Core] Improve reading performance StlIO#14246
Open
loumalouomega wants to merge 20 commits intomasterfrom
Open
[Core] Improve reading performance StlIO#14246loumalouomega wants to merge 20 commits intomasterfrom
StlIO#14246loumalouomega wants to merge 20 commits intomasterfrom
Conversation
- Added file reading functionality to benchmark STL I/O operations. - Replaced hardcoded STL data with file input to better simulate real-world usage. - Implemented error checking for file accessibility. - Adjusted benchmark setup to ensure clean model part creation for accurate timing.
…ce for triangle nodes
…y, elements, and conditions
…g unnecessary functor parameters and improving node handling
…nd parallel execution
…e file access handling
…r floating-point values
…parsing method for floating-point values and streamline whitespace handling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
This PR refactors
StlIOto significantly improve reading performance by deferring node insertion and parallelising entity creation, and adds a Google Benchmark to measure the improvement (-30% time reduction aprox., depends on STL file size).Motivation
The previous implementation created and added nodes to the
ModelPartone by one insideReadLoop, which triggered an expensive ordered-container search on every insertion. Entity creation (elements, conditions, geometries) was also done serially inside the read loop via astd::functionfunctor passed all the way down the call stack.How to test
# Build with benchmark support and run: stl_io_benchmark.exe --benchmark_format=json --benchmark_out=output.json🆕 Changelog
Performance improvements (
stl_io.cpp/stl_io.h)std::vector<Node::Pointer>during facet reading and added to the model part in a single bulk call after the entire solid block is parsed. This avoids repeated searches through the already-inserted node container.new_nodesisreserve()d accordingly, eliminating repeated reallocations.IndexPartition::for_eachusing thread-local storage (TLS), then added to the model part in a single call. Geometry creation falls back to sequential due to an existing memory issue with parallel geometry construction.Refactoring
std::function<void(ModelPart&, NodesArrayType&)>functor passed throughReadSolid→ReadFacet→ReadLoopwith a plainstd::vector<Node::Pointer>&, removing unnecessary indirection.ReadPointnow takesstd::array<double, 3>&by reference instead of returning aPointvalue, avoiding an extra allocation and copy.stl_io.hincludes (removed redundant<string>,<iostream>,<filesystem>,"includes/define.h"; added"includes/kratos_filesystem.h").ApplicationNameApplicationtoKratosCore.New benchmark
kratos/benchmarks/stl_io_benchmark.cpp: a Google Benchmark suite (BM_StlIO) that measuresStlIO::ReadModelParton a real STL file, with a freshModelPartcreated for each iteration.kratos/benchmarks/file.stlas the benchmark input asset.kratos/CMakeLists.txtto build the new benchmark target.Commits