Skip to content

Commit 9fe0c0e

Browse files
committed
Update opt-trace-format.md
1 parent 4dfd91a commit 9fe0c0e

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

‎v3/docs/opt-trace-format.md‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,23 @@ subsequent execution point. If we grep for `stdout` in the trace, we see the fol
585585
This isn't rocket science; but just be aware that `stdout` contains the cumulative contents of the stdout
586586
buffer up to that execution point, not only what's been printed by the most recently executed line.
587587

588+
### Potential stdout optimizations
589+
590+
The default trace format is completely unoptimized. It's designed so as to be "memoryless" -- i.e., a frontend can render an execution state by simply reading that entry and not any of its neighbors.
591+
592+
However, the `stdout` field can often take up A LOT OF SPACE since it's "cumulative" -- i.e., at each step, `stdout` represents the entire contents of the `stdout` buffer, not simply what's been printed out in the current step. Thus, it suffers from N^2 space explosions. Even a simple program like this one prints out an ENORMOUS amount to stdout:
593+
594+
```python
595+
choices = ['pizza', 'pasta', 'salad', 'nachos']
596+
for i in enumerate(choices):
597+
print choices # if you comment this out, the trace is much smaller
598+
choices.append(i)
599+
```
600+
601+
Thus, this is one target for optimization if deemed necessary down the line. However, I'm hesitant to optimize the trace since it makes trace-handling code in the frontend and backend more complicated :/
602+
603+
One elegant way to optimize is to simply store the completed `stdout` buffer ONCE in the trace. And then within each execution point, store a byte index into the buffer. Thus, to render the stdout contents for each point, all we do is slice the buffer from the start to that index. This is similar to the Unix-y idea of file pointers.
604+
588605

589606
## Function Stack Frames
590607

@@ -797,21 +814,3 @@ foo(1)
797814
[TODO: talk about appending `_z` onto `unique_hash` when the frame becomes a zombie.]
798815

799816
[TODO: IMPROVE ME!]
800-
801-
802-
# Notes: Potential optimizations
803-
804-
The default trace format is completely unoptimized. It's designed so as to be "memoryless" -- i.e., a frontend can render an execution state by simply reading that entry and not any of its neighbors.
805-
806-
However, the `stdout` field can often take up A LOT OF SPACE since it's "cumulative" -- i.e., at each step, `stdout` represents the entire contents of the `stdout` buffer, not simply what's been printed out in the current step. Thus, it suffers from N^2 space explosions. Even a simple program like this one prints out an ENORMOUS amount to stdout:
807-
808-
```python
809-
choices = ['pizza', 'pasta', 'salad', 'nachos']
810-
for i in enumerate(choices):
811-
print choices # if you comment this out, the trace is much smaller
812-
choices.append(i)
813-
```
814-
815-
Thus, this is one target for optimization if deemed necessary down the line. However, I'm hesitant to optimize the trace since it makes trace-handling code in the frontend and backend more complicated :/
816-
817-
(One elegant way to optimize is to simply store the completed `stdout` buffer ONCE in the trace. And then within each execution point, store a byte index into the buffer. Thus, to render the stdout contents for each point, all we do is slice the buffer from the start to that index.)

0 commit comments

Comments
 (0)