Repository navigation
Conversation
Three util.DbgPrint calls on the unmarshal path built their argument with pretty.Sprint before DbgPrint checked its off-by-default debugLibrary flag, so every unmarshalled container, list and map entry pretty-printed its whole subtree even with debugging disabled: - ytypes/container.go: "container after unmarshal" - ytypes/list.go: "list after unmarshal" - util/reflect.go: InsertIntoMap Pass util.ValueStrDebug(...) instead, as the neighbouring debug calls already do; it returns "<not calculated>" unless debugging is enabled and is otherwise ValueStr. Remove the now-unused pretty imports. Add BenchmarkUnmarshal in ytypes/schema_tests (100 interfaces x 10 subinterfaces of exampleoc, emitted as RFC7951 JSON).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR: Stop pretty-printing whole subtrees for three debug-only log calls on the unmarshal path when debugging is off. On
a 100-interface × 10-subinterface
Unmarshal, time drops by ~61%, bytes allocated by ~79% and allocations by ~44%.Problem
Three
util.DbgPrintcalls on the unmarshal path built their argument withpretty.Sprint(...)beforeDbgPrintchecked its
debugLibraryflag, which is off by default. So every unmarshalled container, list and map entry pretty-printed its wholesubtree, and the result was thrown away:
ytypes/container.go"container after unmarshal"ytypes/list.go"list after unmarshal"util/reflect.goInsertIntoMapBecause each container prints its whole subtree, and nested containers print again at each level, the wasted work grows with
tree depth as well as size.
Change
util.ValueStrDebug(...)instead, as the neighbouring debug calls already do. It returns"<not calculated>"unlessdebugging is enabled, and is otherwise
ValueStr.github.com/kylelemons/godebug/prettyimports from all three files.BenchmarkUnmarshalinytypes/schema_tests/validate_test.go: 100 interfaces × 10 subinterfaces ofexampleoc(eachwith a description and one IPv4 address), emitted as RFC 7951 JSON and unmarshalled into a fresh
oc.Deviceon each iteration.With debugging disabled, behaviour is unchanged. With debugging enabled, these three lines print
ValueStroutput instead ofpretty.Sprintoutput.Benchmarks (
masterbefore vs. this PR after)BenchmarkUnmarshalwas added tomaster(a1f7f9f) unchanged for the "before" run. Before and after runs were alternatedso machine noise affects both sides equally, then compared with
benchstat:How to read it:
B/opandallocs/opare deterministic (± 0%across all 12 runs), so the 79% and 44% drops are exact, not noise. They match the removed work:pretty.Sprintallocates a string for every subtree it prints.sec/opis noisy (± 25–31%; shared 4-vCPU VM). The effect is still much larger than the spread: the slowest "after"run is well below the fastest "before" run.
p=0.002is the smallest p-valuebenchstat's Mann-Whitney U test can report withn=6per side, meaning every "after" sample beat every "before" sample.Go benchmarks don't fail on a slowdown, so
BenchmarkUnmarshalis evidence for this change and a tool for future comparisons, not a regression gate.