Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add File I/O perf issue (ui.load, manual action) #73

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions EmpowerPlant/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<rect key="frame" x="20" y="0.0" width="374" height="0.0"/>
</progressView>
<stackView opaque="NO" contentMode="scaleToFill" verticalCompressionResistancePriority="751" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="CCo-Yo-I2U">
<rect key="frame" x="8" y="0.0" width="398" height="345"/>
<rect key="frame" x="8" y="0.0" width="398" height="379.5"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="99H-zP-cDK">
<rect key="frame" x="0.0" y="0.0" width="199" height="310.5"/>
Expand Down Expand Up @@ -157,7 +157,7 @@
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="KlN-al-BhV">
<rect key="frame" x="199" y="0.0" width="199" height="345"/>
<rect key="frame" x="199" y="0.0" width="199" height="379.5"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="esb-g7-ouy">
<rect key="frame" x="34" y="0.0" width="131.5" height="34.5"/>
Expand Down Expand Up @@ -239,6 +239,14 @@
<action selector="jsonMainThread:" destination="VXN-aD-u60" eventType="touchUpInside" id="iM7-uu-pjl"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nuh-js-Myu">
<rect key="frame" x="29.5" y="345" width="140.5" height="34.5"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="File I/O on main"/>
<connections>
<action selector="fileIoOnMainThread:" destination="VXN-aD-u60" eventType="touchUpInside" id="WuA-Fh-H1D"/>
</connections>
</button>
</subviews>
</stackView>
</subviews>
Expand Down
11 changes: 11 additions & 0 deletions EmpowerPlant/EmpowerPlantViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class EmpowerPlantViewController: UIViewController {
getAllProductsFromServer()
getAllProductsFromDb()
readCurrentDirectory()
performLongFileOperation()
processProducts()


NotificationCenter.default.addObserver(forName: modifiedDBNotificationName, object: nil, queue: nil) { _ in
self.getAllProductsFromDb()
Expand All @@ -62,6 +64,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 processProducts() {
let span = SentrySDK.span?.startChild(operation: "product_processing")
_ = getIterator(42);
Expand All @@ -78,6 +88,7 @@ class EmpowerPlantViewController: UIViewController {
}
return getIterator(n - 1) + getIterator(n - 2);
}


func readCurrentDirectory() {
let path = FileManager.default.currentDirectoryPath
Expand Down
18 changes: 18 additions & 0 deletions EmpowerPlant/ListAppViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Loading