Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: replace manual function name extraction with std::source_location #3132

Merged

Conversation

dudantas
Copy link
Member

@dudantas dudantas commented Nov 18, 2024

Description

Replaced the previous string concatenation approach for logging function names with std::source_location::current().function_name(). This change significantly improves performance by avoiding runtime string operations. Instead of manually manipulating function signatures using methodName to extract function names, std::source_location provides this information directly in an efficient manner.

Fixes this CPU overload:
image
image

Behaviour

Actual

Concatenating strings with methodName to retrieve function names, which involves runtime overhead.

Expected

Using std::source_location::current().function_name() directly to retrieve function names, reducing runtime string manipulation and improving performance.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested

The updated implementation was tested to ensure that the logs produce the correct function names without the overhead of runtime string manipulation. Benchmarks comparing the old and new approaches demonstrated a noticeable reduction in processing time for logging.

  • Verified that the correct function names are logged.
  • Benchmarked performance improvements.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Replaced the manual string concatenation and extraction for function names with std::source_location::current().function_name(). This change significantly improves performance by avoiding runtime string operations and using a more efficient way to obtain function names.
Copy link

@dudantas dudantas merged commit b5f71a8 into main Nov 19, 2024
35 checks passed
@dudantas dudantas deleted the dudantas/perf-remove-string-comparison-with-method-name branch November 19, 2024 14:53
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.

2 participants