slavapestov/factor — Issue #376: 'n read' in a loop is very slow with small n and large stream size
Author: erg
Created: 2011-11-09 20:49:16+00:00
State: open

image file-info size>> .
101,321,904

```factor
[ image binary [
[ 2 read ] loop
] with-file-reader ] profile
top-down profile.
```

```
depth time ms GC % JIT % FFI % FT %
5 33520.0 14.00 0.00 28.54 0.17 T{ thread f "Listener" ~curry~ ~quotation~ 19 ~box~ f t f H{ }...
6 33519.0 14.00 0.00 28.54 0.17 cleanup
7 33519.0 14.00 0.00 28.54 0.17 2bi
8 33519.0 14.00 0.00 28.54 0.17 2dip
9 33519.0 14.00 0.00 28.54 0.17 dip
10 33519.0 14.00 0.00 28.54 0.17 [ ~quotation~ dip call catchstack* pop* ]
11 33519.0 14.00 0.00 28.54 0.17 cleanup
12 33519.0 14.00 0.00 28.54 0.17 2bi
13 33519.0 14.00 0.00 28.54 0.17 2dip
14 33519.0 14.00 0.00 28.54 0.17 dip
15 33519.0 14.00 0.00 28.54 0.17 [ ~quotation~ dip call catchstack* pop* ]
16 33519.0 14.00 0.00 28.54 0.17 bind
17 30701.0 15.29 0.00 31.16 0.17 loop
18 27420.0 8.62 0.00 26.24 0.18 keep
19 23220.0 10.18 0.00 25.24 0.16 read
20 19161.0 12.34 0.00 28.12 0.16 M\ input-port stream-read-unsafe
21 13754.0 17.19 0.00 36.22 0.16 read-step
22 5164.0 45.78 0.00 94.27 0.04
22 2977.0 0.00 0.00 0.03 0.34 M\ buffer pos>>
22 1665.0 0.00 0.00 0.06 0.36 M\ buffered-port buffer>>
22 1078.0 0.00 0.00 0.09 0.00 M\ buffer fill>>
22 960.0 0.00 0.00 0.10 0.31 M\ buffer pos<<
23 868.0 0.00 0.00 0.12 0.35 M\ fixnum >fixnum
22 366.0 0.00 0.00 0.27 0.00 M\ buffer ptr>>
22 325.0 0.00 0.00 0.00 0.00 M\ fixnum min
22 278.0 0.00 0.00 0.00 0.00 +
22 232.0 0.00 0.00 46.55 0.43 M\ unix (wait-to-read)
23 226.0 0.00 0.00 47.79 0.44 M\ fd refill
24 219.0 0.00 0.00 49.32 0.46 M\ buffered-port buffer>>
24 4.0 0.00 0.00 0.00 0.00 M\ buffer fill>>
24 2.0 0.00 0.00 0.00 0.00 M\ buffer size>>
23 4.0 0.00 0.00 0.00 0.00 M\ disposable disposed>>
23 2.0 0.00 0.00 0.00 0.00 M\ port handle>>
22 222.0 0.00 0.00 0.00 0.00 <
22 182.0 0.00 0.00 0.00 0.00 -
22 180.0 0.00 0.00 0.00 0.00 number=
22 3.0 0.00 0.00 33.33 0.00 (wait-to-read)
23 2.0 0.00 0.00 50.00 0.00 lookup-method
23 1.0 0.00 0.00 0.00 0.00 assoc-stack
22 1.0 0.00 0.00 0.00 0.00 (wait-to-read)/predicate-engine
23 1.0 0.00 0.00 0.00 0.00 assoc-stack
24 1.0 0.00 0.00 0.00 0.00 M\ hashtable at*
21 1834.0 0.00 0.00 0.11 0.33 M\ c-ptr >c-ptr
21 1563.0 0.00 0.00 0.19 0.13 M\ fixnum >fixnum
21 1275.0 0.00 0.00 31.53 0.08 <
21 352.0 0.00 0.00 0.00 0.00 M\ fixnum >integer
20 1525.0 0.00 0.00 0.13 0.26 M\ input-port stream-element-type
20 1124.0 0.00 0.00 0.00 0.18 assoc-stack
21 1019.0 0.00 0.00 0.00 0.20 M\ hashtable at*
20 590.0 0.00 0.00 79.66 0.00 (byte-array)
20 382.0 0.00 0.00 0.00 0.26 M\ byte-array new-sequence
19 1454.0 0.00 0.00 91.47 0.00 resize-byte-array
19 982.0 0.00 0.00 0.20 0.41 [ 2 read ]
19 970.0 0.00 0.00 0.21 0.31 call
19 378.0 0.00 0.00 0.00 0.79 [ call ]
19 159.0 0.00 0.00 0.63 0.63 M\ byte-array resize
18 3248.0 71.71 0.00 72.94 0.09 curry
19 652.0 0.00 0.00 0.00 0.31 callable?
17 1699.0 0.00 0.00 0.06 0.29 M\ curry call
18 1669.0 0.00 0.00 0.06 0.30 uncurry
17 436.0 0.00 0.00 0.00 0.00 call
17 376.0 0.00 0.00 0.00 0.00 when
17 307.0 0.00 0.00 0.00 0.33 [ loop ]
6 1.0 0.00 100.00 100.00 0.00 [ 0 profiling (get-samples) raw-profile-data set-global ]
```