From 922330b9952cb89fbe0b82016dd2ca4a0606e5e1 Mon Sep 17 00:00:00 2001 From: Karl Heinz Struggl Date: Thu, 30 Nov 2023 12:29:52 +0100 Subject: [PATCH] add File I/O perf issue (ui.load, manual action) --- EmpowerPlant/Base.lproj/Main.storyboard | 12 ++++++++++-- EmpowerPlant/EmpowerPlantViewController.swift | 9 +++++++++ EmpowerPlant/ListAppViewController.swift | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/EmpowerPlant/Base.lproj/Main.storyboard b/EmpowerPlant/Base.lproj/Main.storyboard index 4c22f7b..481b5a5 100644 --- a/EmpowerPlant/Base.lproj/Main.storyboard +++ b/EmpowerPlant/Base.lproj/Main.storyboard @@ -69,7 +69,7 @@ - + @@ -157,7 +157,7 @@ - + + diff --git a/EmpowerPlant/EmpowerPlantViewController.swift b/EmpowerPlant/EmpowerPlantViewController.swift index a9c09bd..2125e5d 100644 --- a/EmpowerPlant/EmpowerPlantViewController.swift +++ b/EmpowerPlant/EmpowerPlantViewController.swift @@ -50,6 +50,7 @@ class EmpowerPlantViewController: UIViewController { getAllProductsFromServer() getAllProductsFromDb() readCurrentDirectory() + performLongFileOperation() NotificationCenter.default.addObserver(forName: modifiedDBNotificationName, object: nil, queue: nil) { _ in self.getAllProductsFromDb() @@ -61,6 +62,14 @@ class EmpowerPlantViewController: UIViewController { SentrySDK.reportFullyDisplayed() } + func performLongFileOperation() { + let longString = String(repeating: UUID().uuidString, count: 5_000_000) + let data = longString.data(using: .utf8)! + let filePath = FileManager.default.temporaryDirectory.appendingPathComponent("tmp" + UUID().uuidString) + try! data.write(to: filePath) + try! FileManager.default.removeItem(at: filePath) + } + func readCurrentDirectory() { let path = FileManager.default.currentDirectoryPath do { diff --git a/EmpowerPlant/ListAppViewController.swift b/EmpowerPlant/ListAppViewController.swift index 0134217..d1d32a7 100644 --- a/EmpowerPlant/ListAppViewController.swift +++ b/EmpowerPlant/ListAppViewController.swift @@ -290,6 +290,24 @@ class ListAppViewController: UIViewController { span.finish() } + @IBAction func fileIoOnMainThread(_ sender: Any) { + progressIndicator.isHidden = false + DispatchQueue.global(qos: .utility).async { + let longString = String(repeating: UUID().uuidString, count: 5_000_000) + let data = longString.data(using: .utf8)! + let filePath = FileManager.default.temporaryDirectory.appendingPathComponent("tmp" + UUID().uuidString) + DispatchQueue.main.async { + let transaction = SentrySDK.startTransaction(name: "test", operation: "fileio-on-main", bindToScope: true) + try! data.write(to: filePath) + transaction.finish() + self.progressIndicator.isHidden = true + DispatchQueue.global(qos: .utility).async { + try! FileManager.default.removeItem(at: filePath) + } + } + } + } + // !!!: profiling doesn't correctly collect backtraces with this (armcknight 12 Oct 2023) func factorialRecursive(int x: BigInt) -> BigInt { if x == 0 { return 1 }