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

strstr() a lot slower with ASAN (Linux glibc x86-64) #1832

Open
fuhsnn opened this issue Dec 24, 2024 · 0 comments
Open

strstr() a lot slower with ASAN (Linux glibc x86-64) #1832

fuhsnn opened this issue Dec 24, 2024 · 0 comments

Comments

@fuhsnn
Copy link

fuhsnn commented Dec 24, 2024

After enabling ASAN in the compiler project I work on, I noticed a strstr() call in the tokenization loop is responsible for significant slowdown in ASAN builds.

I believe this is worth reporting since it's a simple change that caused a huge diff, which should make an interesting case for profiling.

In the worst case, ASAN builds are about 170x slower on Skylake, 150x on Zen4, after replacing the strstr() with a loop it's back to normal 2.8x / 2.5x.
The change is fuhsnn/slimcc@eb66a46.

A reproduce script testing ASAN on-off and strstr() with-without, should work on any recent-ish glibc docker:

set -e

git clone https://github.com/fuhsnn/c_files
git clone https://github.com/fuhsnn/slimcc

cd slimcc
git checkout eb66a4619f168af7ce5c34ecc8cc37c82988d51d

cc *.c -o slimcc
echo "Asan 0, strstr 0"
time ./slimcc ../c_files/gcc.c -E -o/dev/null

cc *.c -o slimcc -fsanitize=address
echo "Asan 1 strstr 0"
time ./slimcc ../c_files/gcc.c -E -o/dev/null

git checkout HEAD~1

cc *.c -o slimcc
echo "Asan 0, strstr 1"
time ./slimcc ../c_files/gcc.c -E -o/dev/null

cc *.c -o slimcc -fsanitize=address
echo "Asan 1, strstr 1"
time ./slimcc ../c_files/gcc.c -E -o/dev/null
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

No branches or pull requests

1 participant