A question about compile times for global constants

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@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@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

tests.py (3.32 KB)

analysis.R (1.05 KB)

This is an interesting analysis. I am interested in knowing answer to the
OP’s second question.

Also, what were the some cases where the behaviour is different?

···

On Fri, 17 Nov 2017 at 8:52 AM, Oscar Bonilla via swift-dev < swift-dev@swift.org> wrote:

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:

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:

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

_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

--
Rahul

Sent from iPhone