Commit 82d4a01
committed
SI-8879 fix quadratic reading time in StreamReader
StreamReader.nextEol used to loop all the way to Eol every time an
element was read. That's very costly when lines are long.
Furthermore, it used to call PagedSeq.length, forcing PagedSeq to
load the whole input in memory, even when a single character was read.
nextEol is now saved as part of the state of StreamReader, and is passed
to child readers when created (as long as we do not read past the end of
the line). Thus it computed only once per line, whatever the length.
With the example in the ticket (SI-8879), we get:
* before:
User time (seconds): 82.12
System time (seconds): 0.07
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:21.52
* after:
User time (seconds): 1.05
System time (seconds): 0.06
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.68
* for comparison, using PagedSeqReader directly:
User time (seconds): 1.06
System time (seconds): 0.06
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.69
`isDefinedAt` is used instead of `length` so that pages beyond the
tested index do not need to be read. The test only tests this part.1 parent 3ee2e0f commit 82d4a01
File tree
2 files changed
+55
-11
lines changed- src
- main/scala/scala/util/parsing/input
- test/scala/scala/util/parsing/combinator
2 files changed
+55
-11
lines changedLines changed: 13 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | | - | |
| 54 | + | |
53 | 55 | | |
54 | | - | |
55 | | - | |
| 56 | + | |
| 57 | + | |
56 | 58 | | |
57 | | - | |
| 59 | + | |
58 | 60 | | |
59 | | - | |
| 61 | + | |
60 | 62 | | |
61 | | - | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | | - | |
66 | | - | |
| 67 | + | |
| 68 | + | |
67 | 69 | | |
68 | | - | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
0 commit comments