Skip to content

Use StrongBox<Rect> over object field in GlyphRun #10879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Member

@h3xds1nz h3xds1nz commented May 26, 2025

Description

Swaps an object field with StrongBox<Rect> when caching ink bounds to allow for faster unboxing when required and increase type-safety in the codebase. Given that caching is present on most codepaths, this could theoretically be better nowadays to embed the Rect directly into GlyphRun, but that requires more measurements.

In StrongBox, we just load the field:

   mov       rax,[rsi+8]
   test      rax,rax
   je        short M01_L00
   vmovdqu   ymm1,ymmword ptr [rax+8]
   vmovdqu   ymmword ptr [rbx],ymm1
   mov       rax,rbx

With object, we have to go through type-check etc:

     mov       rdi,[rsi+8]
     test      rdi,rdi
     je        short M01_L01
     mov       rcx,offset MT_System.Windows.Rect
     cmp       [rdi],rcx
     je        short M01_L00
     mov       rdx,rdi
     call      System.Runtime.CompilerServices.CastHelpers.Unbox(Void*, System.Object)
M01_L00:
     vmovdqu   ymm1,ymmword ptr [rdi+8]
     vmovdqu   ymmword ptr [rbx],ymm1
     mov       rax,rbx

With 1 box, 100 returns, this gets down to:

Method Mean [ns] Error [ns] StdDev [ns] Code Size [B] Gen0 Allocated [B]
Original 196.4 ns 1.71 ns 1.60 ns 424 B 0.0048 80 B
PR__EDIT 174.3 ns 1.48 ns 1.32 ns 395 B 0.0048 80 B

Customer Impact

Increased performance, increased type safety and cleaner code.

Regression

No.

Testing

Local build.

Risk

Low.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested a review from a team as a code owner May 26, 2025 09:56
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels May 26, 2025
Copy link

codecov bot commented May 26, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 2.98859%. Comparing base (57fe8ac) to head (ef5c944).
Report is 10 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main     #10879          +/-   ##
===================================================
- Coverage   13.48885%   2.98859%   -10.50026%     
===================================================
  Files           3317       3319           +2     
  Lines         664749     664895         +146     
  Branches       74643      74675          +32     
===================================================
- Hits           89667      19871       -69796     
- Misses        572488     644844       +72356     
+ Partials        2594        180        -2414     
Flag Coverage Δ
Debug 2.98859% <0.00000%> (-10.50026%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant