Skip to content

Commit b046cd5

Browse files
committed
Update v3/docs/opt-trace-format.md
1 parent edceec1 commit b046cd5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ which was the code `x = 5`. If you look at the
184184
[visualization at this step](http://pythontutor.com/visualize.html#code=x+%3D+5%0Ay+%3D+10%0Az+%3D+x+%2B+y&mode=display&cumulative=false&py=2&curInstr=1),
185185
you'll see that `x` has been assigned to `5`.
186186

187+
Ok let's keep marching to the next execution point, which is the one that corresponds to "Step 3 of 3"
188+
in the frontend:
187189

188190
```javascript
189191
{
@@ -204,6 +206,20 @@ you'll see that `x` has been assigned to `5`.
204206
}
205207
```
206208

209+
Now `line` is 3, because we're about to execute line 3 (we just executed lines 1 and 2). Notice that there is a
210+
new key-value pair in`globals` showing that `y` has been assigned to `10`. No surprises here, since we just
211+
executed the line `y = 10`.
212+
213+
Ok now this is where I want to talk about `ordered_globals`, which is a list of global variables (i.e.,
214+
keys in `globals`) in the order that the frontend should visualize them. The backend appends variable
215+
names in their order of appearance throughout execution. Why is this list necessary? Because `globals`
216+
is an object whose keys are unsorted, so if you don't also keep an `ordered_globals` sorted list,
217+
then the visualization might end up being jarring. For instance, at one execution point, it might
218+
render `x` and then `y`, and at the next execution point, it might render `y` and then `x`, thereby
219+
causing the visualization to "jitter" unnecessarily. And I've found that it looks aesthetically pleasing
220+
when variables are sorted in their order of appearance as you step forwards through execution.
221+
222+
207223
```javascript
208224
{
209225
"ordered_globals": [

0 commit comments

Comments
 (0)