Swift: Turn on optimization or release mode for a single class

Viewed 60

I have a class that takes 3 seconds to process data in Debug mode, but only takes 100ms in Release mode. There is obviously something wrong with it but all tests pass so I don't need any Debug features when using it.

Is there a way to make Xcode run the project in Debug mode but do all Release optimization for this single class?

The only workaround I can think of is to turn this into a framework with a release compile flag but that seems like a bit overkill.

1 Answers

The only workaround I can think of is to turn this into a framework with a release compile flag but that seems like a bit overkill.

This is the only stable way to do this at the moment (with Xcode 13). One more option is that you can try doing some timing measurements, it might be possible to rearrange your code so that even the debug codegen gives better results.

If this is throwaway code, you can try marking individual functions with the underscored attribute @_optimize(speed).

I'll repeat the disclaimer at the top of the doc:

WARNING: This information is provided primarily for compiler and standard library developers. Usage of these attributes outside of the Swift monorepo is STRONGLY DISCOURAGED.

Related