From 5d1e4b5906b813d724922403fe29bc68ac31df30 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 29 Dec 2017 10:14:19 -0800 Subject: [PATCH] Revert "Retry semaphore wait when lines are still missing" This reverts commit 069a50b893e68fcecb9dd6b1b3e852fbb59217f2. As mentioned in PR review comments, this change adds to complexity without noticeably improving results. It also matches my observation that a second time through the loop is very rare. --- XiEditor/LineCache.swift | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/XiEditor/LineCache.swift b/XiEditor/LineCache.swift index b8d5b01..12a9a8f 100644 --- a/XiEditor/LineCache.swift +++ b/XiEditor/LineCache.swift @@ -240,30 +240,20 @@ class LineCacheLocked { } func blockingGet(lines lineRange: LineRange) -> [Line?] { - var deadline: DispatchTime? = nil - var lines = inner.linesForRange(range: lineRange) - var count = 0 - while true { - let missingLines = lineRange.enumerated() - .filter( { lines.count > $0.offset && lines[$0.offset] == nil }) - .map( { $0.element }) - if missingLines.isEmpty { - break - } - if deadline == nil { - deadline = .now() + .milliseconds(MAX_BLOCK_MS) - } else if .now() > deadline! { - break - } + let lines = inner.linesForRange(range: lineRange) + let missingLines = lineRange.enumerated() + .filter( { lines.count > $0.offset && lines[$0.offset] == nil }) + .map( { $0.element }) + if !missingLines.isEmpty { // TODO: should we send request to core? - print("waiting for lines: (\(missingLines.first!), \(missingLines.last!)) \(count)") + print("waiting for lines: (\(missingLines.first!), \(missingLines.last!))") //TODO: this timing + printing code can come out // when we're comfortable with the performance and // the timeout duration let blockTime = mach_absolute_time() inner.isWaiting = true inner.unlock() - let waitResult = inner.waitingForLines.wait(timeout: deadline!) + let waitResult = inner.waitingForLines.wait(timeout: .now() + .milliseconds(MAX_BLOCK_MS)) inner.lock() let elapsed = mach_absolute_time() - blockTime @@ -279,11 +269,9 @@ class LineCacheLocked { } print("finished waiting: \(elapsed / 1000)us \(waitResult)") } - lines = inner.linesForRange(range: lineRange) - count += 1 } - return lines + return inner.linesForRange(range: lineRange) } func applyUpdate(update: [String: AnyObject]) -> InvalSet {