Skip to content

Poor performance of udivmod in zig compiler_rt #13523

Description

@plajjan

Zig Version

0.10.0

Steps to Reproduce and Observed Behavior

I have a program implemented in Acton (https://github.com/actonlang/acton/), a programming language which generates C and uses zig cc to build an executable. In one particular program, using zig cc leads to a program that is roughly 50x times slower compared to gcc / clang:

kll@Boxy:~/terastream/Programming-Language-Benchmarks/bench/algorithm/edigits$ ~/terastream/acton/dist/bin/actonc 1.act --quiet && time ./1 30000 > /dev/null

real	0m3.255s
user	0m3.260s
sys	0m0.012s
kll@Boxy:~/terastream/Programming-Language-Benchmarks/bench/algorithm/edigits$ ~/terastream/acton/dist/bin/actonc 1.act --quiet --cc $(which gcc) && time ./1 30000 > /dev/null

real	0m0.154s
user	0m0.158s
sys	0m0.013s
kll@Boxy:~/terastream/Programming-Language-Benchmarks/bench/algorithm/edigits$ ~/terastream/acton/dist/bin/actonc 1.act --quiet --cc $(which clang) && time ./1 30000 > /dev/null

real	0m0.150s
user	0m0.152s
sys	0m0.013s
kll@Boxy:~/terastream/Programming-Language-Benchmarks/bench/algorithm/edigits$ 

I recorded some data for a flamegraph, where we can see that we spend most of the time in udivmod. I assume compiler_rt here refers to the zig compiler_rt and not clangs, right? I mean, otherwise it would have been slow with clang too..

2022-11-11-154009_1496x496_scrot

As for reproduction, I can certainly add in the Acton program etc but I suspect it would be more convenient with a smaller C program that showcases the problem. However, before I do that, I would like to understand whether this type of bug report is accepted or if it's working as intended? Like is there a performance promise / idea of performance level to reach under which things are considered buggy?

Is there any way to workaround this? Can I somehow tell zig cc to use clangs udivmod?

Expected Behavior

I want my zig cc compiled program to run as fast as when I compile it using clang or gcc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.optimization

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions