Skip to content

Commit

Permalink
[test] Repro for GC thrashing
Browse files Browse the repository at this point in the history
This is bug #2123.

Unrelated:

[spec/ysh-builtin-eval] Nicer example
  • Loading branch information
Andy C committed Nov 16, 2024
1 parent 5a67993 commit f4283e5
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
12 changes: 10 additions & 2 deletions spec/ysh-builtin-eval.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ var s = io->evalExpr(ex, dollar0='z', pos_args=:|a b c|, vars=vars)

echo $s

proc where(; pred) {
proc my-where (; pred) {
# note: for line in (io.stdin) is messed up by spec test framework

while read --raw-line (&line) {
Expand All @@ -682,10 +682,18 @@ proc where(; pred) {
}
}

seq 5 | where [_line ~== 2 or _line ~== 4]

seq 5 | my-where [_line ~== 2 or _line ~== 4]
echo ---

seq 5 10 | my-where [_line % 2 === 1]

## STDOUT:
z a b hello
2
4
---
5
7
9
## END
14 changes: 14 additions & 0 deletions test/bug-2123.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

demo() {
local ysh=_bin/cxx-opt/ysh
ninja $ysh

#OILS_GC_STATS=1 $ysh test/bug-2123.ysh

# max RSS
# 246
/usr/bin/time --format '%e %M' $ysh test/bug-2123.ysh
}

"$@"
78 changes: 78 additions & 0 deletions test/bug-2123.ysh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Run with _bin/cxx-opt/ysh

proc filter (; predicate) {
for line in (io.stdin) {
if (io->evalExpr(predicate, vars={_val: fromJson8(line)})) {
write -- $line
}
}
}

#
# Setup
#

var f = '_tmp/b1'

for i in (0 ..= 100_000) {
json write ({}, space=0)
} > $f

#
# Benchmarks
#

var N = 2

proc with-default {
write -- u'get() with default\n'
write -- 'BEFORE ------------------------------------------------------'

for _ in (0 ..< N) {
time for line in (io.stdin) {
call fromJson8(line)
} < $f
write
}

echo 'FILTER with default'
time filter [get(_val, 'missing-key', 0) === 0] < $f >/dev/null

write -- 'AFTER -------------------------------------------------------'

for _ in (0 ..< N) {
time for line in (io.stdin) {
call fromJson8(line)
} < $f
write
}
}

proc without-default {
write -- u'get() without default\n'
write -- 'BEFORE ------------------------------------------------------'

for _ in (0 ..< N) {
time for line in (io.stdin) {
call fromJson8(line)
} < $f
write
}

echo 'FILTER without default'
time filter [get(_val, 'missing-key')] < $f #>/dev/null

write -- 'AFTER -------------------------------------------------------'

for _ in (0 ..< N) {
time for line in (io.stdin) {
call fromJson8(line)
} < $f
write
}
}


with-default
without-default

4 changes: 4 additions & 0 deletions test/ysh-runtime-errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ test-eggex-convert-func() {
_ysh-expr-error 'var pat = / <capture d+: evalExpr> /; var m = "10" => search(pat) => group(1)'
}

test-eval-expr() {
_ysh-expr-error 'var expr = ^[x + 1]; = io->evalExpr(expr, pos_args=[42])'
}

test-int-convert() {
_ysh-expr-error '= int({})'
_ysh-expr-error '= int([])'
Expand Down

0 comments on commit f4283e5

Please sign in to comment.