Skip to content

Minor perf improvements related to number parsing#266

Merged
sonals merged 4 commits intoXilinx:main-gefrom
sonals:speed
Apr 16, 2026
Merged

Minor perf improvements related to number parsing#266
sonals merged 4 commits intoXilinx:main-gefrom
sonals:speed

Conversation

@sonals
Copy link
Copy Markdown
Member

@sonals sonals commented Apr 15, 2026

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

@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Signed-off-by: Sonal Santan <sonal.santan@amd.com>
@github-actions
Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to std::stoul().
Comments suppressed due to low confidence (1)

src/cpp/common/assembler_state.cpp:170

  • handlers is now a function-local static but the stored lambdas capture this. That means the map is initialized once using the first assembler_state instance that calls parse_num_arg(), and subsequent calls (including from other instances) will dereference the wrong this pointer. 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 an assembler_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.

Comment thread src/cpp/common/assembler_state.cpp

#include "utils.h"

#include "regex_wrapper.h"
Comment thread src/cpp/common/assembler_state.cpp Outdated
…such instance is needed per class object

Signed-off-by: Sonal Santan <sonal.santan@amd.com>
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

virtual ~assembler_state() = default;

private:
const std::unordered_map<std::string, std::function<uint32_t(const std::string&)>> handlers = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = {
                                                                                     ^

sonals added 2 commits April 15, 2026 13:27
Signed-off-by: Sonal Santan <sonal.santan@amd.com>
Signed-off-by: Sonal Santan <sonal.santan@amd.com>
@sonals sonals merged commit 06d63af into Xilinx:main-ge Apr 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants