Skip to content

[Syntax] Add init(unsafeCasting: Syntax) to concrete node types #2924

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

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Dec 21, 2024

init(unsafeCasting:) should only be used when we are absolutely sure the syntax kind matches the type, and only in perf critial places. Use it in SyntaxEnum, SyntaxVisitor, and SyntaxRewriter.

Also, rework SyntaxVisitor/SyntaxRewriter visitation, eliminating unnecessary ARC traffic.

Baseline:

'-[PerformanceTest.PerfTests testEmptyRewriter]' measured [Time, seconds] average: 1.626, relative standard deviation: 0.492%, values: [1.645482, 1.618930, 1.620801, 1.619107, 1.621778, 1.620863, 1.621619, 1.629248, 1.633502, 1.628365],
'-[PerformanceTest.PerfTests testEmptyVisitor]' measured [Time, seconds] average: 1.169, relative standard deviation: 0.825%, values: [1.195887, 1.166237, 1.164091, 1.167106, 1.167065, 1.175714, 1.164696, 1.160530, 1.163220, 1.167872]

With this patch:

'-[PerformanceTest.PerfTests testEmptyRewriter]' measured [Time, seconds] average: 1.281, relative standard deviation: 0.991%, values: [1.317752, 1.279236, 1.281419, 1.273362, 1.273581, 1.277479, 1.283182, 1.277359, 1.273263, 1.273686]
'-[PerformanceTest.PerfTests testEmptyVisitor]' measured [Time, seconds] average: 0.933, relative standard deviation: 0.710%, values: [0.952931, 0.931542, 0.933043, 0.932171, 0.931005, 0.929917, 0.931035, 0.930155, 0.931712, 0.929429]

This patch eliminates ARC during visitation funcs, but we still need to retain the parent Syntax.Info when constructing Syntax.

@rintaro
Copy link
Member Author

rintaro commented Dec 21, 2024

@swift-ci Please test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

LGTM. I would be curious to see the performance numbers before merging.

'init(unsafeCasting:)' should only be used when we are absolutely sure
the syntax kind matches the type, and only in perf critical places.
Use it in SyntaxEnum, SyntaxVisitor, and SyntaxRewriter.

Also, rework SyntaxVisitor/SyntaxRewriter visitation, eliminating
unnecessary ARC traffic.
@rintaro rintaro force-pushed the syntax-unsafe-casting branch from 2e4c3b0 to a25f490 Compare January 2, 2025 19:38
@rintaro
Copy link
Member Author

rintaro commented Jan 2, 2025

As per offline discussion with Alex, renamed init(_unsafeCasting:) to init(unsafeCasting:)

@rintaro
Copy link
Member Author

rintaro commented Jan 2, 2025

@swift-ci Please test

@rintaro rintaro enabled auto-merge January 2, 2025 19:39
@rintaro rintaro changed the title [Syntax] Add init(_unsafeCasting: Syntax) to concrete node types [Syntax] Add init(unsafeCasting: Syntax) to concrete node types Jan 2, 2025
@rintaro rintaro merged commit f6e7f0f into swiftlang:main Jan 2, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants