You signed in with another tab or window. Reload to refresh your session.
8000
You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tests: serialization round trips for the wire types #48
Done. The 1000-frame trace found a quadratic trimmer.
The trimmer was quadratic, and the test the issue asked for is what showed it
_trim_to_budget dropped the deepest trace frame one at a time and
re-encoded the whole google.rpc.Status after each drop. With 1000 frames and
only a few dozen fitting, that is ~950 full re-encodes of a large message.
trace frames
before
after
200
0.44s
0.02s
1000
8.29s
0.08s
A trace of 1000 frames is what an infinite recursion produces, so this is the
realistic worst case rather than an invented one -- and it is the error most
likely to be slow to report.
The fix is a binary search over one cap. The old loop's result is always min(len(traces), cap) for a single shared cap, because each pass removes
one frame from whichever payload is currently longest. So the answer is
identical and the cost goes from O(n) re-encodes to O(log n). The existing
tests -- head kept, tail dropped, truncated set, identity survives -- all
pass unchanged, which is the evidence that the semantics did not move.
The new test also pins that the cap is maximal, not merely sufficient: one
more frame must not fit. Verified red-before-green by making the search stop a
frame early.
Round trips
tests/nanopynix/rpc/test_wire_round_trips.py, 27 tests, every one through
real bytes (bytes(msg) then Msg().parse(...)). An object-to-object
comparison would pass while a field never reached the wire.
Six messages had no mention anywhere in the suite: BuildResultList, CallArg, CallArgAttrs, CallArgList, RemoteCallArg, ErrorTrace. The CallArg tree is the argument encoding for a Nix function call and had no test
of any kind, so it is now decoded by _worker_eval.py's own _call_arg_to_python rather than by a copy of it.
The falsy scalars are the point of half the file. "", 0, False, 0.0 are
all falsy, and every converter here asks if field is not None. A converter
rewritten with if field: would turn each of them into None, and only after
a serialize-and-parse cycle, because that is when proto3 presence is decided.
Measured: all survive, with their types -- True does not come back as 1.
The recursive DerivationOutputs tree is covered three levels deep.
One thing found and deliberately not fixed
A deeply nested DeepValue raises a bare RecursionError. Max depth per
stage, one {"k": [...]} per level:
stage
under pytest
plain
python_to_deep_value
239
over 400
bytes(...)
79
82
DeepValue().parse(...)
63
65
Two columns because the first measurement was wrong: beartype instruments
nanopynix's callables under the suite and not under a plain interpreter, so it
costs the encoder about 40% of its depth and the betterproto stages three
levels. The conclusion holds either way and the gap makes it sharper -- betterproto2's serializer and parser are the limit, by a factor of three,
not nanopynix's converter.
Pinned rather than corrected. Deciding what a caller should see instead of a
third-party RecursionError is hostile-input work, so it belongs to #49.
Activity
Lillecarl commentedon Aug 2, 2026
Done. The 1000-frame trace found a quadratic trimmer.
The trimmer was quadratic, and the test the issue asked for is what showed it
_trim_to_budgetdropped the deepest trace frame one at a time andre-encoded the whole
google.rpc.Statusafter each drop. With 1000 frames andonly a few dozen fitting, that is ~950 full re-encodes of a large message.
A trace of 1000 frames is what an infinite recursion produces, so this is the
realistic worst case rather than an invented one -- and it is the error most
likely to be slow to report.
The fix is a binary search over one cap. The old loop's result is always
min(len(traces), cap)for a single sharedcap, because each pass removesone frame from whichever payload is currently longest. So the answer is
identical and the cost goes from O(n) re-encodes to O(log n). The existing
tests -- head kept, tail dropped,
truncatedset, identity survives -- allpass unchanged, which is the evidence that the semantics did not move.
The new test also pins that the cap is maximal, not merely sufficient: one
more frame must not fit. Verified red-before-green by making the search stop a
frame early.
Round trips
tests/nanopynix/rpc/test_wire_round_trips.py, 27 tests, every one throughreal bytes (
bytes(msg)thenMsg().parse(...)). An object-to-objectcomparison would pass while a field never reached the wire.
Six messages had no mention anywhere in the suite:
BuildResultList,CallArg,CallArgAttrs,CallArgList,RemoteCallArg,ErrorTrace. TheCallArgtree is the argument encoding for a Nix function call and had no testof any kind, so it is now decoded by
_worker_eval.py's own_call_arg_to_pythonrather than by a copy of it.The falsy scalars are the point of half the file.
"",0,False,0.0areall falsy, and every converter here asks
if field is not None. A converterrewritten with
if field:would turn each of them intoNone, and only aftera serialize-and-parse cycle, because that is when proto3 presence is decided.
Measured: all survive, with their types --
Truedoes not come back as1.The recursive
DerivationOutputstree is covered three levels deep.One thing found and deliberately not fixed
A deeply nested
DeepValueraises a bareRecursionError. Max depth perstage, one
{"k": [...]}per level:python_to_deep_valuebytes(...)DeepValue().parse(...)Two columns because the first measurement was wrong: beartype instruments
nanopynix's callables under the suite and not under a plain interpreter, so it
costs the encoder about 40% of its depth and the betterproto stages three
levels. The conclusion holds either way and the gap makes it sharper --
betterproto2's serializer and parser are the limit, by a factor of three,
not nanopynix's converter.
Pinned rather than corrected. Deciding what a caller should see instead of a
third-party
RecursionErroris hostile-input work, so it belongs to #49.test(rpc): round-trip the wire types, and cut a quadratic trimmer