Skip to content

Add JSON output format for remoting #1415

@michaellwest

Description

@michaellwest

Summary

Relates to #1374 — CliXml serialization via System.Management.Automation.Serializer is the main performance bottleneck in SPE remoting. This adds a -OutputFormat Json option as a faster alternative.

Problem

ConvertTo-CliXml uses reflection to walk the entire object graph with deep type information. For large result sets (hundreds of Sitecore items), this dominates response time. The existing -Raw switch bypasses serialization but returns unstructured .ToString() output.

Solution

New -OutputFormat parameter (CliXml | Json | Raw) on the remoting pipeline:

  • Server (RemoteScriptCall.ashx.cs): Parses outputFormat query param, adds JSON branch using ConvertTo-Json -Depth 3 -Compress with {"output":[], "errors":[]} envelope, sets Content-Type: application/json
  • Client (Invoke-RemoteScript.ps1): New -OutputFormat param on Invoke-RemoteScript, backwards-compat mapping from -Raw switch, JSON parse with fallback to CliXml for old servers
  • Benchmark: Updated scenarios with 500 objects × 10 properties to stress-test serialization

Benchmark Results (500 objects × 10 properties)

Format P50 (ms) Avg (ms)
CliXml 596 827
Json 350 347
Raw 134 139

JSON is 2.4x faster than CliXml at P50 while preserving structured property data.

Backwards Compatibility

  • -Raw switch continues to work unchanged
  • Old client → new server: rawOutput=true maps to raw format
  • New client → old server: Falls back to CliXml with a warning if JSON parse fails

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions