Skip to content

Optimize failureBreakpoint(). #655

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged

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:
0000000000000660	sub	sp, sp, #0x30
0000000000000664	stp	x29, x30, [sp, #0x20]
0000000000000668	add	x29, sp, #0x20
000000000000066c	adrp	x8, 0 ; 0x0
0000000000000670	add	x0, x8, #0x0
0000000000000674	add	x1, sp, #0x8
0000000000000678	mov	x2, #0x21
000000000000067c	mov	x3, #0x0
0000000000000680	bl	0x680
0000000000000684	mov	x8, #0x1
0000000000000688	adrp	x9, 0 ; 0x0
000000000000068c	add	x9, x9, #0x0
0000000000000690	str	x8, [x9]
0000000000000694	add	x0, sp, #0x8
0000000000000698	bl	0x698
000000000000069c	ldp	x29, x30, [sp, #0x20]
00000000000006a0	add	sp, sp, #0x30
00000000000006a4	ret

After

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

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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
performance Performance issues tools integration Integration of swift-testing into tools/IDEs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants