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

test: use a longer span to compare efficient implementations #2277

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (void)testGenerateProfileData
}
if (efficiently) {
[launchArguments
addObject:@"--io.sentry.sample.trending-movies.launch-arg.blur-images-on-bg-thread"];
addObject:@"--io.sentry.sample.trending-movies.launch-arg.efficient-implementation"];
}
app.launchArguments = launchArguments;
[app launch];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -62,7 +62,7 @@
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "--io.sentry.sample.trending-movies.blur-images-on-bg-thread"
argument = "--io.sentry.sample.trending-movies.efficient-implementation"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,34 @@ class MovieCellConfigurator {
case let .success(url):
if let url = url {
print("[TrendingMovies] got poster image URL for movie: \(movie.id) (\(movie.title)): \(url)")
cell.downloadTask = KingfisherManager.shared.retrieveImage(with: url) { [weak cell] imageResult in
switch imageResult {
case let .success(image):
print("[TrendingMovies] set poster image for movie: \(movie.id) (\(movie.title))")
cell?.posterImage = image.image
case let .failure(error):
print(error)
cell?.posterImage = nil
if ProcessInfo.processInfo.arguments.contains("--io.sentry.sample.trending-movies.launch-arg.efficient-implementation") {
cell.downloadTask = KingfisherManager.shared.retrieveImage(with: url) { [weak cell] imageResult in
switch imageResult {
case let .success(image):
print("[TrendingMovies] set poster image for movie: \(movie.id) (\(movie.title))")
cell?.posterImage = image.image
case let .failure(error):
print(error)
cell?.posterImage = nil
}
}
} else {
cell.uncachedDownloadTask = cell.uncachedURLSession.downloadTask(with: URLRequest(url: url), completionHandler: { [weak cell] downloadedURL, _, error in
if error != nil || downloadedURL == nil {
cell?.posterImage = nil
return
}

guard let downloadedURLString = downloadedURL?.relativePath else {
cell?.posterImage = nil
return
}

DispatchQueue.main.async {
cell?.posterImage = UIImage(contentsOfFile: downloadedURLString)
}
})
cell.uncachedDownloadTask?.resume()
}
} else {
cell.posterImage = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class MovieCollectionViewCell: UICollectionViewCell {
}

var downloadTask: DownloadTask?
var uncachedDownloadTask: URLSessionDownloadTask?
let uncachedURLSession = URLSession(configuration: .ephemeral)

private let posterImageView: UIImageView = {
let imageView = UIImageView()
Expand Down Expand Up @@ -151,7 +153,7 @@ class MovieCollectionViewCell: UICollectionViewCell {
}

private func blurPosterImage(_ image: UIImage, completion: @escaping (UIImage?) -> Void) {
let efficiently = ProcessInfo.processInfo.arguments.contains("--io.sentry.sample.trending-movies.launch-arg.blur-images-on-bg-thread")
let efficiently = ProcessInfo.processInfo.arguments.contains("--io.sentry.sample.trending-movies.launch-arg.efficient-implementation")
func performBlur() {
let blurredImage = ImageEffects.createBlurredBackdrop(image: image, downsamplingFactor: 1.0, blurRadius: 20.0, tintColor: nil, saturationDeltaFactor: 2.0)
if efficiently {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class MoviesViewController: UICollectionViewController, UICollectionViewDelegate
}
}

private var scrollingSpan: Tracer.SpanHandle?

init(subtitleStyle: MovieCellConfigurator.SubtitleStyle = .genre, enableStartupTimeLogging: Bool, sortFunction: SortFunction? = nil, dataFetchingFunction: @escaping DataFetchingFunction) {
let layout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 0.0
Expand Down Expand Up @@ -167,11 +169,19 @@ class MoviesViewController: UICollectionViewController, UICollectionViewDelegate
// MARK: UIScrollViewDelegate

override func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollingSpan == nil {
let efficiently = ProcessInfo.processInfo.arguments.contains("--io.sentry.sample.trending-movies.launch-arg.efficient-implementation")
scrollingSpan = Tracer.startSpan(name: "movie-list-scroll-\(efficiently ? "efficiently" : "inefficiently")")
}
if scrollView.contentSize.height - (scrollView.contentOffset.y + scrollView.bounds.height) <= 300.0 {
fetchNextPage()
}
}

override func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
scrollingSpan?.end()
}

// MARK: Data

private func fetchNextPage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension Tracer {

SentrySDK.configureScope { scope in
scope.setTag(value: setUpInDidFinishLaunching ? "didFinishLaunching" : "willFinishLaunching", key: "launch-method")
scope.setTag(value: "\(ProcessInfo.processInfo.arguments.contains("--io.sentry.sample.trending-movies.launch-arg.blur-images-on-bg-thread"))", key: "efficient-implementation")
scope.setTag(value: "\(ProcessInfo.processInfo.arguments.contains("--io.sentry.sample.trending-movies.launch-arg.efficient-implementation"))", key: "efficient-implementation")
}
}
}
Expand Down