Repository navigation
Treat framework types as opaque beyond depth 1 in object tree renderer - #88
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 quick update, and for the clear explanation of the branch name. Both changes from the last review are applied well, and the new collection tests are good.
I found one new problem that came from moving the framework-type check. Please see the comment below. It is a one-line fix, but it needs to be fixed before we can merge. After that, this PR looks good.
| if (depth > 1 && IsFrameworkType(type)) | ||
| { | ||
| sb.Append(WebUtility.HtmlEncode(value.ToString() ?? "")); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Moving this check below the cycle check created a small new bug.
The cycle check above (line 86) adds the object to seen. The other branches remove it again before they return (see lines 99, 119, and 124). But this branch returns without removing it. So the object stays in seen forever.
This is a problem because some framework objects are shared. For example, typeof(double) is always the same object in memory. When two properties hold the same Type object, the first one is shown correctly, but the second one shows [circular reference]. That is wrong output.
Example: a list of columns where every column has DataType = typeof(double). The first column shows System.Double. All the other columns show [circular reference].
The fix is one line:
| if (depth > 1 && IsFrameworkType(type)) | |
| { | |
| sb.Append(WebUtility.HtmlEncode(value.ToString() ?? "")); | |
| return; | |
| } | |
| if (depth > 1 && IsFrameworkType(type)) | |
| { | |
| if (!type.IsValueType) seen.Remove(value); | |
| sb.Append(WebUtility.HtmlEncode(value.ToString() ?? "")); | |
| return; | |
| } |
Could you also add a small test for this? For example: an object with two properties that both hold typeof(int). The output should show System.Int32 two times, and no [circular reference].
… shared types
- Move IEnumerable check before the framework-type opacity check so
nested collections (List<string>, arrays, etc.) still expand at all
depths instead of being hidden by IsFrameworkType
- Match exact namespaces (System / System.* / Microsoft / Microsoft.*)
instead of StartsWith("System") which also matched user namespaces
like Systematic or SystemTools
- Move the framework-type opacity check before cycle detection so shared
framework instances (e.g. typeof(int) is always the same object in
memory) render via ToString() instead of triggering false
[circular reference] output when they appear in sibling properties
- Add tests: nested collections at depth 1 and 2 still show their items;
two properties holding typeof(int) both render without circular refs
Signed-off-by: JoeJoeflyn <[email protected]>
5e7fc0f to
38c3641
Compare
|
Thanks for catching this. Your suggested |
|
Verified locally, all 1217 tests pass, and you were right that the reorder was needed instead of my one line idea. Thank you. |
|
Happy to help! Glad it worked out |
Summary
Fixes VERSO-007 — object tree view producing oversized output for complex framework types.
IsFrameworkTypehelper toObjectTreeRenderer(checks if a type's namespace isSystem,System.*,Microsoft, orMicrosoft.*)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 internalsIEnumerable) still expand at all depths — the collection check runs before the framework-type opacity check so nestedList<string>, arrays, etc. are not hiddenBackground
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)FormatAsync_NestedCollectionAtDepth1_StillShowsItems— asserts nested collections still show their items at depth 1FormatAsync_NestedCollectionAtDepth2_StillShowsItems— asserts nested collections still show their items at depth 2+Verso.Testssuite: 1216 passed, 0 failedverso servebrowser editor