Commit 9ae3069
committed
Reduce memory usage of query service result sets
Reading large result sets via the query service kept far more memory
alive than the decoded data itself required.
The converted result set referenced the source protobuf message through
`_ResultSet.columns` and through `_Row._columns` on every row. With the
upb protobuf backend, any reference into a message pins its entire arena,
so the raw `message.rows` payload stayed alive for the whole lifetime of
the result set — the decoded Python objects and the full source protobuf
were held simultaneously.
Detach the result set from the source arena: copy the schema into a
standalone message and store a shared tuple of column names on rows
instead of the proto columns, so the source arena is released right
after conversion. Also copy the Arrow `data` payload out of the arena.
Additionally give the row/struct dict subclasses `__slots__` to drop the
redundant per-row instance `__dict__`, and make `_DotDict.__getattr__`
raise `AttributeError` instead of leaking `KeyError` (which had broken
`copy.copy`/`copy.deepcopy` of rows).
Peak RSS for a streaming read of 20x20k rows (results kept) drops from
~953 MB to ~298 MB.1 parent f2c742d commit 9ae3069
2 files changed
Lines changed: 107 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| |||
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
86 | | - | |
| 91 | + | |
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
| |||
351 | 356 | | |
352 | 357 | | |
353 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
354 | 369 | | |
355 | 370 | | |
356 | 371 | | |
| |||
375 | 390 | | |
376 | 391 | | |
377 | 392 | | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
378 | 398 | | |
379 | | - | |
380 | | - | |
| 399 | + | |
| 400 | + | |
381 | 401 | | |
382 | 402 | | |
383 | | - | |
| 403 | + | |
384 | 404 | | |
385 | 405 | | |
386 | 406 | | |
387 | 407 | | |
388 | 408 | | |
389 | 409 | | |
390 | 410 | | |
391 | | - | |
| 411 | + | |
392 | 412 | | |
393 | 413 | | |
394 | 414 | | |
| |||
399 | 419 | | |
400 | 420 | | |
401 | 421 | | |
402 | | - | |
| 422 | + | |
403 | 423 | | |
404 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
405 | 427 | | |
406 | 428 | | |
407 | 429 | | |
| |||
422 | 444 | | |
423 | 445 | | |
424 | 446 | | |
| 447 | + | |
| 448 | + | |
425 | 449 | | |
426 | 450 | | |
427 | 451 | | |
428 | 452 | | |
429 | 453 | | |
430 | 454 | | |
431 | | - | |
| 455 | + | |
432 | 456 | | |
433 | | - | |
| 457 | + | |
434 | 458 | | |
435 | 459 | | |
436 | 460 | | |
| |||
455 | 479 | | |
456 | 480 | | |
457 | 481 | | |
| 482 | + | |
| 483 | + | |
458 | 484 | | |
459 | 485 | | |
460 | 486 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | | - | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
9 | 11 | | |
10 | 12 | | |
11 | 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 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
12 | 82 | | |
13 | 83 | | |
14 | 84 | | |
| |||
0 commit comments