[swift-users] Performance critical code in Swift
Игорь Никитин
devnikor at icloud.com
Sat Oct 1 16:31:30 CDT 2016
It's isn't just about storing, but also parsing (I parse big json with yajl, the C json parser) and processing that data.
And right, name and location is strings
> 2 окт. 2016 г., в 0:24, Jens Persson <jens at bitcycle.com> написал(а):
>
> There's no reason why writing data to disk should be slower in Swift than in C/C++.
>
> (For the name and location properties, I assume you want to save Strings, a sequence of characters or something rather than just the value of the UnsafePointer<UInt8>.)
>
>> On Sat, Oct 1, 2016 at 11:22 PM, Игорь Никитин <devnikor at icloud.com> wrote:
>> I got it. Thanks for your tips!
>>
>>> 2 окт. 2016 г., в 0:13, Jens Persson <jens at bitcycle.com> написал(а):
>>>
>>
>>> You could write some examples in both C and Swift in order to gain experience in how to write your Swift code so that it will (probably) run as fast as (or faster than) your corresponding C code.
>>>
>>> I've done this for a number of different performance critical things and it is often possible to get the Swift version as fast as the C version.
>>>
>>> (If you find something that is not possible (or unnecessarily cumbersome) to write as fast in Swift as in C, you could probably file a bug/improvement on bugs.swift.org. I did this some time ago when I noticed that Swift's optimizer missed an opportunity to unroll loops in a certain situation and it turned out that a fix/optimizer-improvement was already on its way.)
>>>
>>> You must of course profile/microbenchmark your code in some meaningful way, setting all relevant compiler flags for both C and Swift, preventing dead code elimination, measuring average or perhaps median times of lots of tests, making sure what should and shouldn't be statically knowable, etc.
>>>
>>> In Swift you probably want -O -whole-module-optimization, and (rarely) you might want/need to disable safety checks.
>>>
>>> /Jens
>>>
>>>
>>>
>>>> On Sat, Oct 1, 2016 at 10:33 PM, Daniel Dunbar via swift-users <swift-users at swift.org> wrote:
>>>> Yes, it is possible. Exactly how much use of Unsafe style idioms and other performance-focused "workarounds" it requires depends a lot on the code in question. Can you say more about your problem area?
>>>>
>>>> - Daniel
>>>>
>>>> > On Oct 1, 2016, at 1:30 PM, Игорь Никитин via swift-users <swift-users at swift.org> wrote:
>>>> >
>>>> > Hello!
>>>> > Is it possible for Swift to be as fast as C when writing performance critical code? Of course if using C Standard Library for instead of Foundation (and so on) and getting rid of dynamic dispatch and reference types.
>>>> > Or I need just to use C?
>>>> > _______________________________________________
>>>> > swift-users mailing list
>>>> > swift-users at swift.org
>>>> > https://lists.swift.org/mailman/listinfo/swift-users
>>>>
>>>> _______________________________________________
>>>> swift-users mailing list
>>>> swift-users at swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-users
>>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161002/cdb7f9aa/attachment.html>
More information about the swift-users
mailing list