Minor perf improvements related to number parsing#266
Conversation
|
clang-tidy review says "All clean, LGTM! 👍" |
Signed-off-by: Sonal Santan <sonal.santan@amd.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
There was a problem hiding this comment.
Pull request overview
This PR targets a known hotspot in the assembler’s numeric argument parsing, aiming to reduce overhead in assembler_state::parse_num_arg() during large testcases (e.g., aie4 multi_graph).
Changes:
- Makes the handler lookup table for prefix-based parsing static to avoid per-call construction.
- Reworks
tile_<col>_<row>parsing using a compiled regex and extracts row/col via capture groups. - Simplifies hex parsing by passing the full
"0x..."string tostd::stoul().
Comments suppressed due to low confidence (1)
src/cpp/common/assembler_state.cpp:170
handlersis now a function-localstaticbut the stored lambdas capturethis. That means the map is initialized once using the firstassembler_stateinstance that callsparse_num_arg(), and subsequent calls (including from other instances) will dereference the wrongthispointer. This is incorrect and can also introduce cross-instance/thread issues. Consider keeping the table non-static, or make the table static but store non-capturing callables (e.g., free functions/member-function pointers that take anassembler_state&/assembler_state*as an explicit parameter).
static const std::unordered_map<std::string, std::function<uint32_t(const std::string&)>> handlers = {
{"@", [this](const std::string& s) -> uint32_t {
//If string start with '@': it can be either pad name or label name
auto key = s.substr(1);
if (m_scratchpad.find(key) != m_scratchpad.end())
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| #include "utils.h" | ||
|
|
||
| #include "regex_wrapper.h" |
…such instance is needed per class object Signed-off-by: Sonal Santan <sonal.santan@amd.com>
| virtual ~assembler_state() = default; | ||
|
|
||
| private: | ||
| const std::unordered_map<std::string, std::function<uint32_t(const std::string&)>> handlers = { |
There was a problem hiding this comment.
warning: member 'handlers' of type 'const std::unordered_map<std::string, std::function<uint32_t (const std::string &)>>' (aka 'const unordered_map<basic_string, function<unsigned int (const basic_string &)>>') is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
const std::unordered_map<std::string, std::function<uint32_t(const std::string&)>> handlers = {
^Signed-off-by: Sonal Santan <sonal.santan@amd.com>
Signed-off-by: Sonal Santan <sonal.santan@amd.com>
Problem solved by the commit
Number parsing was taking up 28% of time for the aie4 multi_graph testcase. Improve speed by removing redundant string operations and making the handler table static..
Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered
How problem was solved, alternative solutions (if any) and why they were rejected
valgrind analysis identified the hotspot.
Risks (if any) associated the changes in the commit
Low
What has been tested and how, request additional testing if necessary
ctest validated
Documentation impact (if any)
NA