Brace expansion

Asked in r/openwrt but was left without an answer.

Can someone explain why brace expansion is so slooow in openwrt 24.10 compared to 23.05.05

To reproduce generate a colon delimited 3000 line file.

    for i in {1..3000}; do
    echo “$i:$i:$i:$i:$i:$i” >> myfile.txt
    done

Btw u have to explicitly call bash for aforementioned script to work

Now make another script

    #!/bin/bash
    my_file=$(< “myfile.txt”)
    my_file=${my_file//:/ }
    echo “$my_file”

And try same with

    my_file=$(tr ‘:’ ‘ ‘ <<<$my_file)

On ubuntu laptop all the test show that expansion is faster than with tr. in openwrt its exact opposite. In theory expansion should work faster too because it doesnt spawn a new process to deal with it but does everything in the same process so no subshell nothing.

I can confirm that expansion was working faster in 23.05.05

for q in `seq 1 1000` ...
1 Like

Im sorry but what this has to do with my question?

1 Like

Bash is not primary shell in OpenWrt, there are dozen ways to squeeze regex from bash.
Do some ltrace/strace mayb€ you find your answer. sed s/:/\ /g is even faster, i cannot get amy of samples to scratch measurable time.

Unfortunately there are no library or system calls in brace expansion it relies solely on bash to do that. So strace or ltrace are useless in this case.

Absolutely not specific to OpenWrt.

I would agree but why its working with 23.05.05? Exact same bash version.