Skip to content

Treat framework types as opaque beyond depth 1 in object tree renderer - #87

Closed
JoeJoeflyn wants to merge 1 commit into
DataficationSDK:mainfrom
JoeJoeflyn:fix/verso-003-fsharp-anonymous-records
Closed

JoeJoeflyn wants to merge 1 commit into
DataficationSDK:mainfrom
JoeJoeflyn:fix/verso-003-fsharp-anonymous-records

Conversation

@JoeJoeflyn

Copy link
Copy Markdown
Contributor

Summary

Fixes VERSO-007 — object tree view producing oversized output for complex framework types.

  • Add IsFrameworkType helper to ObjectTreeRenderer (checks if a type's 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

Background

System.Type exposes ~40 public properties. One of them, Assembly, exposes DefinedTypes — 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, a System.ArgumentException: The JSON value of length N is too large crash during auto-save.

This implements the planned improvement from KNOWN-ISSUES.md:

Consider treating types from runtime assemblies (System., System.Reflection.) as opaque beyond depth 1, rendering them via .ToString() rather than expanding their full property graphs.

Test plan

  • FormatAsync_FrameworkTypeAtDepth2_DoesNotExpandReflectionInternals — asserts DefinedTypes does not appear in output when a System.Type property is at depth 2
  • FormatAsync_FrameworkTypeAtDepth1_StillExpandable — asserts framework types at depth 1 still expand (not fully opaque)
  • Full Verso.Tests suite: 1214 passed, 0 failed
  • Manual verification in verso serve browser editor — TypeHolder with System.Type property renders correctly at depths 1 and 2

- 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 TorreyBetts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IsFrameworkType return false when the type is an IEnumerable.

This keeps your reflection fix and still shows the items of normal lists and arrays.

Comment on lines +258 to +259
return ns.StartsWith("System", StringComparison.Ordinal)
|| ns.StartsWith("Microsoft", StringComparison.Ordinal);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Suggested change
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.*).

@JoeJoeflyn JoeJoeflyn closed this Jul 24, 2026
@JoeJoeflyn
JoeJoeflyn deleted the fix/verso-003-fsharp-anonymous-records branch July 24, 2026 07:10
@JoeJoeflyn

Copy link
Copy Markdown
Contributor Author

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 fix/verso-003-fsharp-anonymous-records to fix/verso-007-framework-type-opacity — the old name was leftover from an earlier abandoned attempt at VERSO-003, which turned out to already be fixed in the current FSharp.Compiler.Service version).

Changes in #88:

  • Moved the IEnumerable check before the framework-type opacity check so nested collections still expand at all depths
  • Changed StartsWith("System") to exact System / System.* / Microsoft / Microsoft.* matching
  • Added two tests for nested collections at depth 1 and 2
  • Full suite: 1216 passed, 0 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants