Repository navigation
Treat framework types as opaque beyond depth 1 in object tree renderer - #87
JoeJoeflyn wants to merge 1 commit into
Conversation
- Add IsFrameworkType helper (namespace starts with System or Microsoft) - Render framework types via ToString() at depth 2+ instead of expanding their property graphs, cutting off the Type → Assembly → DefinedTypes explosion path that wasted the 512 KB output budget on reflection internals - Framework types at depth 0-1 still expand so users can inspect immediate properties; user types expand at all depths - Add tests: framework type at depth 2 does not expand reflection internals; framework type at depth 1 remains expandable Fixes VERSO-007. Signed-off-by: JoeJoeflyn <[email protected]>
TorreyBetts
left a comment
There was a problem hiding this comment.
Thank you for the pull request. The change is clean and it is well documented, and the tests are a nice touch.
I left two small suggestions in the code below.
One question, just out of curiosity: the branch name is fix/verso-003-fsharp-anonymous-records, but this PR is about VERSO-007 (framework types). Was this branch first made for another issue? It is no problem either way. I only want to make sure I understand it correctly.
| // thousands of types × ~40 properties, wasting the output budget and | ||
| // producing hundreds of MB of HTML). At depth 0–1 the user can still | ||
| // expand framework types to see their immediate properties. (VERSO-007) | ||
| if (depth > 1 && IsFrameworkType(type)) |
There was a problem hiding this comment.
Thanks for this fix. It solves the reflection problem well.
One thing to check: this if runs before the collection code below (around line 104). So it also changes normal collections. For example, a List<string> or a string[] inside another object (at depth 2 or deeper) will now show only its type name instead of its items. Many users keep lists inside their objects, so they could lose useful output here.
Could you let collections still expand? Two simple options:
- move the collection check (
value is IEnumerable ... and not string) above this block, or - make
IsFrameworkTypereturnfalsewhen the type is anIEnumerable.
This keeps your reflection fix and still shows the items of normal lists and arrays.
| return ns.StartsWith("System", StringComparison.Ordinal) | ||
| || ns.StartsWith("Microsoft", StringComparison.Ordinal); |
There was a problem hiding this comment.
Small note: StartsWith("System") also matches user namespaces that only begin with the same letters. For example Systematic or SystemTools. Types in those namespaces would become opaque too, but that is not the goal.
Could you match the exact namespace instead?
| return ns.StartsWith("System", StringComparison.Ordinal) | |
| || ns.StartsWith("Microsoft", StringComparison.Ordinal); | |
| return ns == "System" || ns.StartsWith("System.", StringComparison.Ordinal) | |
| || ns == "Microsoft" || ns.StartsWith("Microsoft.", StringComparison.Ordinal); |
This matches only the real framework namespaces (System, System.*, Microsoft, Microsoft.*).
|
Thanks for the review! Both suggestions are applied in the replacement PR #88 (this one was auto-closed when the head branch was renamed from Changes in #88:
|
Summary
Fixes VERSO-007 — object tree view producing oversized output for complex framework types.
IsFrameworkTypehelper toObjectTreeRenderer(checks if a type's namespace starts withSystemorMicrosoft)ToString()at depth 2+ instead of expanding their property graphs, cutting off theType → Assembly → DefinedTypesexplosion path that wasted the 512 KB output budget on reflection internalsBackground
System.Typeexposes ~40 public properties. One of them,Assembly, exposesDefinedTypes— potentially thousands of types, each with their own ~40-property graphs. Across 6 recursion levels this produced hundreds of MB of HTML, causing the 512 KB cap to truncate the user's actual data and, in worst cases, aSystem.ArgumentException: The JSON value of length N is too largecrash during auto-save.This implements the planned improvement from
KNOWN-ISSUES.md:Test plan
FormatAsync_FrameworkTypeAtDepth2_DoesNotExpandReflectionInternals— assertsDefinedTypesdoes not appear in output when aSystem.Typeproperty is at depth 2FormatAsync_FrameworkTypeAtDepth1_StillExpandable— asserts framework types at depth 1 still expand (not fully opaque)Verso.Testssuite: 1214 passed, 0 failedverso servebrowser editor —TypeHolderwithSystem.Typeproperty renders correctly at depths 1 and 2