Skip to content
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

Slow division on iOS 15.0 vs 16.4 #59

Open
oscbyspro opened this issue Aug 14, 2023 · 4 comments
Open

Slow division on iOS 15.0 vs 16.4 #59

oscbyspro opened this issue Aug 14, 2023 · 4 comments
Labels
availability in an SDK near you brrr such code, much wow time the passing of time is hard at work

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Aug 14, 2023

I think this is a low-priority issue, but still (#58):

The difference appears to be between iOS 15 and iOS 16.4:

// Swift 5.8, iPhone 13 Pro, iOS 16.4 (0.027 seconds, 0.019 seconds)

Test Case '-[NBKDoubleWidthKitBenchmarks.NBKDoubleWidthBenchmarksOnDivisionAsUInt256 testQuotientAndRemainder]' passed (0.027 seconds).
Test Case '-[NBKDoubleWidthKitBenchmarks.NBKDoubleWidthBenchmarksOnDivisionAsUInt256 testQuotientAndRemainderDividingByDigit]' passed (0.019 seconds).

// Swift 5.8, iPhone 13 Pro, iOS 15.0 (0.233 seconds, 0.547 seconds)

Test Case '-[NBKDoubleWidthKitBenchmarks.NBKDoubleWidthBenchmarksOnDivisionAsUInt256 testQuotientAndRemainder]' passed (0.233 seconds).
Test Case '-[NBKDoubleWidthKitBenchmarks.NBKDoubleWidthBenchmarksOnDivisionAsUInt256 testQuotientAndRemainderDividingByDigit]' passed (0.547 seconds).
@oscbyspro oscbyspro added brrr such code, much wow availability in an SDK near you labels Aug 14, 2023
@oscbyspro oscbyspro changed the title Slow division on iOS 15.0 compared to iOS 16.4 Slow division on iOS 15.0 vs 16.4 Aug 14, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 14, 2023

All of the time is spend calling __udivmodti4, according to Instruments. So, basically, UInt.dividingFullWidth(_:) is slow as snails on iOS 15. Is my interpretation correct? And, if so, why? It seems so random.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 22, 2023

It seems everything is slower on Xcode 14.2 (iPhone 14 Pro), but not as slow as above.

@wadetregaskis
Copy link

Probably iOS 16 was the first iOS release to pick up this optimisation of __udivmodti4 by @danlark1. Seems a bit late - that patch was integrated in 2020, iOS 16 was released in 2022 - but maybe that's the speed of Swift/LLVM in this regard.

It's pretty funny that the implementation prior to that patch was based on a C translation of PowerPC assembly for a 64-bit divmod function for 32-bit architectures. 😆 (The PowerPC Compiler Writer’s Guide)

@oscbyspro oscbyspro added the time the passing of time is hard at work label Nov 13, 2023
@oscbyspro
Copy link
Owner Author

Those were interesting reads. Thanks! I appreciate that you found the source of the problem. Since it has been solved, in a way, I suppose I'll close this issue when iOS 15 gets phased out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
availability in an SDK near you brrr such code, much wow time the passing of time is hard at work
Projects
None yet
Development

No branches or pull requests

2 participants