Skip to content

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Aug 30, 2024

failureBreakpoint() currently has optimizations disabled which produces some significant assembly for what's supposed to be a no-op. Enabling optimizations and marking its magic value as @exclusivity(unchecked) reduces it to a single indirect store.

This is probably not the hottest hot path in the library (since it will only be called when a test is failing) but the whole point of the function is to be a no-op, and without this change it's quite noisy and includes a whole function call into the Swift runtime (see the bl instructions below.)

arm64

Before

_$s7Testing17failureBreakpointyyF: 0000000000000660subsp, sp, #0x30 0000000000000664stp	x29, x30, [sp, #0x20] 0000000000000668addx29, sp, #0x20 000000000000066c	adrp	x8, 0 ; 0x0 0000000000000670addx0, x8, #0x0 0000000000000674addx1, sp, #0x8 0000000000000678movx2, #0x21 000000000000067cmovx3, #0x0 0000000000000680bl0x680 0000000000000684movx8, #0x1 0000000000000688adrp	x9, 0 ; 0x0 000000000000068caddx9, x9, #0x0 0000000000000690strx8, [x9] 0000000000000694addx0, sp, #0x8 0000000000000698bl0x698 000000000000069c	ldp	x29, x30, [sp, #0x20] 00000000000006a0addsp, sp, #0x30 00000000000006a4ret

After

_$s7Testing17failureBreakpointyyF: 0000000000000660adrp	x8, 0 ; 0x0 0000000000000664strxzr, [x8] 0000000000000668ret

Note this disassembly comes from the intermediate .o file generated for the relevant source file, so addresses aren't available yet. Neither function actually attempts to write to 0x0.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.
`failureBreakpoint()` currently has optimizations disabled which produces some significant assembly for what's supposed to be a no-op. Enabling optimizations and marking its magic value as `@exclusivity(unchecked)` reduces it to a single indirect store.
@grynspan grynspan added tools integration 🛠️ Integration of swift-testing into tools/IDEs performance 🏎️ Performance issues swift-6.1 labels Aug 30, 2024
@grynspan grynspan self-assigned this Aug 30, 2024
@grynspan
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@stmontgomery stmontgomery left a comment

Choose a reason for hiding this comment

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

Nice!

@grynspan grynspan merged commit 294544a into main Sep 4, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/optimize-failureBreakpoint branch September 4, 2024 20:14
@grynspan grynspan added this to the Swift 6.1 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance 🏎️ Performance issues tools integration 🛠️ Integration of swift-testing into tools/IDEs

3 participants