MiSawa / xq

Pure rust implementation of jq
MIT License
318 stars 18 forks source link

Deep nesting of string interpolation slows parser #37

Closed itchyny closed 2 years ago

itchyny commented 2 years ago

Nesting string interpolation extremely slows the parser (not execution because adding invalid token to the query does not exit quickly).

❯ time xq -n '"\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\(1+2)")")")")")")")")")")")")")")")")")")")")")"'
"3"
xq -n   16.01s user 0.02s system 99% cpu 16.034 total

❯ time jq -n '"\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\("\(1+2)")")")")")")")")")")")")")")")")")")")")")"'
"3"
jq -n   0.00s user 0.00s system 65% cpu 0.010 total
MiSawa commented 2 years ago

Thank you for reporting! Seems to be explosion of alt, though not sure which component of parser is causing it.

Perhaps it could be resolved by adding cuts like this example, though wasn't able to locate appropriate parts to add to yet. Or maybe #2 is easier.

MiSawa commented 2 years ago

Actually it probably isn't as easy as adding cuts. Need to figure out what branch is causing the issue.

MiSawa commented 2 years ago

Fixed in #52