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

xkbcomp/scanner: avoid unneeded strdup of IDENT tokens #642

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

bluetech
Copy link
Member

@bluetech bluetech commented Feb 3, 2025

The allocation is immediately discarded, either turned into a keysym or
an atom. So use an sval slice into the input string instead strdup'ing.

memusage ./release/bench-compile-keymap --iter=1000 --layout us,de --variant ,neo

Before:

Memory usage summary: heap total: 534063576, heap peak: 581022, stack peak: 18848
        total calls   total memory   failed calls
 malloc|   11240525      291897104              0
realloc|    1447657      192307328              0  (nomove:37629, dec:0, free:0)
 calloc|     430573       49859144              0
   free|   13993903      534063576

After:

Memory usage summary: heap total: 506839909, heap peak: 581022, stack peak: 18960
        total calls   total memory   failed calls
 malloc|    8016419      264673437              0
realloc|    1447657      192307328              0  (nomove:37278, dec:0, free:0)
 calloc|     430573       49859144              0
   free|    0769797      506839909

src/xkbcomp/parser.y Outdated Show resolved Hide resolved
@bluetech bluetech added this to the 1.9.0 milestone Feb 3, 2025
@bluetech bluetech force-pushed the scanner-improvements-3 branch from 584b1a1 to eee74dc Compare February 5, 2025 10:38
@wismill wismill added compile-keymap Indicates a need for improvements or additions to keymap compilation performance labels Feb 5, 2025
The allocation is immediately discarded, either turned into a keysym or
an atom. So use an sval slice into the input string instead strdup'ing.

memusage ./release/bench-compile-keymap --iter=1000 --layout us,de --variant ,neo

Before:

    Memory usage summary: heap total: 534063576, heap peak: 581022, stack peak: 18848
            total calls   total memory   failed calls
     malloc|   11240525      291897104              0
    realloc|    1447657      192307328              0  (nomove:37629, dec:0, free:0)
     calloc|     430573       49859144              0
       free|   13993903      534063576

After:

    Memory usage summary: heap total: 506839909, heap peak: 581022, stack peak: 18960
            total calls   total memory   failed calls
     malloc|    8016419      264673437              0
    realloc|    1447657      192307328              0  (nomove:37278, dec:0, free:0)
     calloc|     430573       49859144              0
       free|   10769797      506839909

Signed-off-by: Ran Benita <[email protected]>
@bluetech bluetech force-pushed the scanner-improvements-3 branch from eee74dc to 2fcc3e8 Compare February 5, 2025 21:55
@bluetech bluetech merged commit f4e9528 into xkbcommon:master Feb 5, 2025
5 checks passed
@bluetech bluetech deleted the scanner-improvements-3 branch February 5, 2025 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compile-keymap Indicates a need for improvements or additions to keymap compilation performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants