Swift 3.0 Compiler and Sourcekitservice Memory Allocation

I ran into a stranger problem in my iOS swift 3 project.

Scenarios:

I have a list of os objects that have a property, as you can see below:

var total: Double { var sum = 0.0 for item in self.products! { sum += item.price ?? 0 } return sum } 

In the same class, there is another property called distance:

 var distance: Double? 

My compilation of projects works fine when I find the maximum distance value, for example:

 let minDistance = est?.max(by: { (e1, e2) -> Bool in return e1.distance! < e2.distance! }) 

However, when I try to find the maximum prive value, my project compilations become too slow and consume a lot of memory in fast and sourcekitservice processes (over 40 GB).

 let maxValue = est?.max(by: { (e1, e2) -> Bool in return e1.total < e2.total }) 

When I use the if if let block, it works fine:

 if let e = est { let minDistance = e.max(by: { (e1, e2) -> Bool in return e1.distance! < e2.distance! }) let maxValue = est?.max(by: { (e1, e2) -> Bool in return e1.total < e2.total }) } 

The problem in this case is when I use minDistance objects! and maxValue. If I do not use these variables, the problem does not occur.

SourceKitService memory allocation: enter image description here enter image description here

Has anyone already encountered a similar problem?

+5
source share

Source: https://habr.com/ru/post/1261499/


All Articles