[swift-dev] A question about compile times for global constants

Oscar Bonilla obonilla at linkedin.com
Thu Nov 16 18:51:54 CST 2017


Hi swift-dev,

I was trying to determine the most efficient way to store constants in swift without impacting compilation time. I started off by creating a python script (attached) that just creates a swift file with a single type with 1, 2, 4, 8, …, 1024 fields. The type could be enum, struct, or class. And the field declaration can be ‘case’ (for enum), ‘let’, or ‘static let’.

Now to the interesting part, I plotted the size of the resulting .o file and this is what I got:

[cid:2abbcede-fca6-44d2-9a84-72a6546d02a8 at namprd21.prod.outlook.com]


Looking at this it looks like enum/case is the way to go, however I also plotted the time it took to compile the swift file:

[cid:9a4cb1fa-556b-48c0-87bc-8bf03458ceae at namprd21.prod.outlook.com]


One thing that surprised me is that for some common cases (enum/case, class/let, and struct/let) the compilation time seems at least quadratic.

Is this something that is well known or have I stumbled on a corner-case?

I’m attaching both the script I used for generating the tests and the R script used for plotting. (Please excuse the small images, I tried sending the email with large images and it bounced).

What is the most space/compile time efficient way to handle constants?

Cheers,

-Oscar


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171117/c68c01b1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-3.png
Type: image/png
Size: 50579 bytes
Desc: PastedGraphic-3.png
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171117/c68c01b1/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-2.png
Type: image/png
Size: 46155 bytes
Desc: PastedGraphic-2.png
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171117/c68c01b1/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tests.py
Type: text/x-python-script
Size: 3399 bytes
Desc: tests.py
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171117/c68c01b1/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: analysis.R
Type: application/octet-stream
Size: 1075 bytes
Desc: analysis.R
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171117/c68c01b1/attachment.obj>


More information about the swift-dev mailing list