[CmdletBinding()]
param([string]$BaselineRef='1abf972d6338db143c3b83808a83e1756f8ad16c')
$ErrorActionPreference='Stop'
$taskRoot=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../../..'))
$output=Join-Path $taskRoot ('build/MonacoInit/HostComparison-'+[DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds())
[void][IO.Directory]::CreateDirectory($output)
$baseline=Join-Path $output 'Baseline'
$oldTiering=$env:DOTNET_TieredCompilation
Push-Location $taskRoot
try {
$commit=(& git rev-parse ($BaselineRef+'^{commit}')).Trim()
if($LASTEXITCODE -ne 0){throw 'The baseline must resolve to a Git commit.'}
& git archive --format=zip ('--output='+(Join-Path $output 'Baseline.zip')) $commit
if($LASTEXITCODE -ne 0){throw 'Could not export the baseline.'}
Expand-Archive -LiteralPath (Join-Path $output 'Baseline.zip') -DestinationPath $baseline
$project=Join-Path $output 'BaselineProbe.csproj'
$reference=[Security.SecurityElement]::Escape((Join-Path $baseline 'Source/XFESystem.Browser/XFESystem.Browser.csproj'))
$profile=[Security.SecurityElement]::Escape((Join-Path $PSScriptRoot 'MonacoProfile.cs'))
$canvas=[Security.SecurityElement]::Escape((Join-Path $PSScriptRoot '../ProductionProbe/WindowsTextCanvas.cs'))
@"
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net10.0-windows</TargetFramework><UseWindowsForms>true</UseWindowsForms><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><EnableDefaultCompileItems>false</EnableDefaultCompileItems></PropertyGroup>
<ItemGroup><ProjectReference Include="$reference"/><Compile Include="$profile"/><Compile Include="$canvas"/><Compile Include="Main.cs"/></ItemGroup>
</Project>
"@ | Set-Content -LiteralPath $project -Encoding UTF8
'MonacoProfile.Run(Path.GetFullPath(args[0]), args[1]);' | Set-Content -LiteralPath (Join-Path $output 'Main.cs') -Encoding UTF8
# Suppress tier promotion variance; initial JIT still belongs to cold host
# startup. The separate native image comparison contains no host JIT.
$env:DOTNET_TieredCompilation='0'
& dotnet run --project $project -c Release --artifacts-path (Join-Path $output 'BeforeArtifacts') -- $baseline Before *> (Join-Path $output 'Before.log')
if($LASTEXITCODE -ne 0){throw ('Baseline Monaco profile failed: '+$output)}
& dotnet run --project (Join-Path $PSScriptRoot 'PreviewProfile.csproj') -c Release --artifacts-path (Join-Path $output 'AfterArtifacts') -- $taskRoot After --monaco *> (Join-Path $output 'After.log')
if($LASTEXITCODE -ne 0){throw ('Current Monaco profile failed: '+$output)}
$beforePath=Get-Content -LiteralPath (Join-Path $output 'Before.log') -Encoding UTF8 | Select-Object -Last 1
$afterPath=Get-Content -LiteralPath (Join-Path $output 'After.log') -Encoding UTF8 | Select-Object -Last 1
$before=Get-Content -LiteralPath $beforePath -Raw -Encoding UTF8 | ConvertFrom-Json
$after=Get-Content -LiteralPath $afterPath -Raw -Encoding UTF8 | ConvertFrom-Json
if(!$before.Passed -or !$after.Passed){throw 'A full initialization/editing profile failed.'}
$rows=@()
foreach($kind in @('ShortCSharp','LongCSharp')) {
$old=@($before.Cases | Where-Object {$_.Kind -ceq $kind})
$new=@($after.Cases | Where-Object {$_.Kind -ceq $kind})
if($old.Count -ne 5 -or $new.Count -ne 5){throw 'Missing repeated cases.'}
for($i=0;$i -lt 5;$i++) {
if($old[$i].RenderSha256 -cne $new[$i].RenderSha256){throw ('Actual token view changed: '+$kind)}
}
$oldTime=@($old.FullReadyMilliseconds | Sort-Object)[2];$newTime=@($new.FullReadyMilliseconds | Sort-Object)[2]
$rows+=[ordered]@{Kind=$kind;BeforeMedianMilliseconds=$oldTime;AfterMedianMilliseconds=$newTime;Speedup=$oldTime/$newTime;
BeforeTokenizationFullModelReads=$old[0].TokenizationWork.FullModelReads;AfterTokenizationFullModelReads=$new[0].TokenizationWork.FullModelReads;
BeforeAllocatedBytes=$old[0].AllocatedBytes;AfterAllocatedBytes=$new[0].AllocatedBytes;ActualViewTokensEqual=$true}
}
[ordered]@{Kind='MonacoFullInitializationHostComparison';Passed=$true;HostOnly=$true;NativeAcceptance=$false;
BaselineCommit=$commit;Before=$beforePath;After=$afterPath;Rows=$rows} | ConvertTo-Json -Depth 5 |
Set-Content -LiteralPath (Join-Path $output 'Comparison.json') -Encoding UTF8
Write-Output ('Host Monaco comparison: '+(Join-Path $output 'Comparison.json'))
} finally {$env:DOTNET_TieredCompilation=$oldTiering;Pop-Location}
[CmdletBinding()]
param([string]$BaselineRef='1abf972d6338db143c3b83808a83e1756f8ad16c')
$ErrorActionPreference='Stop'
$taskRoot=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../../..'))
$output=Join-Path $taskRoot ('build/MonacoInit/HostComparison-'+[DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds())
[void][IO.Directory]::CreateDirectory($output)
$baseline=Join-Path $output 'Baseline'
$oldTiering=$env:DOTNET_TieredCompilation
Push-Location $taskRoot
try {
$commit=(& git rev-parse ($BaselineRef+'^{commit}')).Trim()
if($LASTEXITCODE -ne 0){throw 'The baseline must resolve to a Git commit.'}
& git archive --format=zip ('--output='+(Join-Path $output 'Baseline.zip')) $commit
if($LASTEXITCODE -ne 0){throw 'Could not export the baseline.'}
Expand-Archive -LiteralPath (Join-Path $output 'Baseline.zip') -DestinationPath $baseline
$project=Join-Path $output 'BaselineProbe.csproj'
$reference=[Security.SecurityElement]::Escape((Join-Path $baseline 'Source/XFESystem.Browser/XFESystem.Browser.csproj'))
$profile=[Security.SecurityElement]::Escape((Join-Path $PSScriptRoot 'MonacoProfile.cs'))
$canvas=[Security.SecurityElement]::Escape((Join-Path $PSScriptRoot '../ProductionProbe/WindowsTextCanvas.cs'))
@"
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net10.0-windows</TargetFramework><UseWindowsForms>true</UseWindowsForms><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><EnableDefaultCompileItems>false</EnableDefaultCompileItems></PropertyGroup>
<ItemGroup><ProjectReference Include="$reference"/><Compile Include="$profile"/><Compile Include="$canvas"/><Compile Include="Main.cs"/></ItemGroup>
</Project>
"@ | Set-Content -LiteralPath $project -Encoding UTF8
'MonacoProfile.Run(Path.GetFullPath(args[0]), args[1]);' | Set-Content -LiteralPath (Join-Path $output 'Main.cs') -Encoding UTF8
# Suppress tier promotion variance; initial JIT still belongs to cold host
# startup. The separate native image comparison contains no host JIT.
$env:DOTNET_TieredCompilation='0'
& dotnet run --project $project -c Release --artifacts-path (Join-Path $output 'BeforeArtifacts') -- $baseline Before *> (Join-Path $output 'Before.log')
if($LASTEXITCODE -ne 0){throw ('Baseline Monaco profile failed: '+$output)}
& dotnet run --project (Join-Path $PSScriptRoot 'PreviewProfile.csproj') -c Release --artifacts-path (Join-Path $output 'AfterArtifacts') -- $taskRoot After --monaco *> (Join-Path $output 'After.log')
if($LASTEXITCODE -ne 0){throw ('Current Monaco profile failed: '+$output)}
$beforePath=Get-Content -LiteralPath (Join-Path $output 'Before.log') -Encoding UTF8 | Select-Object -Last 1
$afterPath=Get-Content -LiteralPath (Join-Path $output 'After.log') -Encoding UTF8 | Select-Object -Last 1
$before=Get-Content -LiteralPath $beforePath -Raw -Encoding UTF8 | ConvertFrom-Json
$after=Get-Content -LiteralPath $afterPath -Raw -Encoding UTF8 | ConvertFrom-Json
if(!$before.Passed -or !$after.Passed){throw 'A full initialization/editing profile failed.'}
$rows=@()
foreach($kind in @('ShortCSharp','LongCSharp')) {
$old=@($before.Cases | Where-Object {$_.Kind -ceq $kind})
$new=@($after.Cases | Where-Object {$_.Kind -ceq $kind})
if($old.Count -ne 5 -or $new.Count -ne 5){throw 'Missing repeated cases.'}
for($i=0;$i -lt 5;$i++) {
if($old[$i].RenderSha256 -cne $new[$i].RenderSha256){throw ('Actual token view changed: '+$kind)}
}
$oldTime=@($old.FullReadyMilliseconds | Sort-Object)[2];$newTime=@($new.FullReadyMilliseconds | Sort-Object)[2]
$rows+=[ordered]@{Kind=$kind;BeforeMedianMilliseconds=$oldTime;AfterMedianMilliseconds=$newTime;Speedup=$oldTime/$newTime;
BeforeTokenizationFullModelReads=$old[0].TokenizationWork.FullModelReads;AfterTokenizationFullModelReads=$new[0].TokenizationWork.FullModelReads;
BeforeAllocatedBytes=$old[0].AllocatedBytes;AfterAllocatedBytes=$new[0].AllocatedBytes;ActualViewTokensEqual=$true}
}
[ordered]@{Kind='MonacoFullInitializationHostComparison';Passed=$true;HostOnly=$true;NativeAcceptance=$false;
BaselineCommit=$commit;Before=$beforePath;After=$afterPath;Rows=$rows} | ConvertTo-Json -Depth 5 |
Set-Content -LiteralPath (Join-Path $output 'Comparison.json') -Encoding UTF8
Write-Output ('Host Monaco comparison: '+(Join-Path $output 'Comparison.json'))
} finally {$env:DOTNET_TieredCompilation=$oldTiering;Pop-Location}