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

Performance imporvement in UIView fillToSuperview() #540

Merged
merged 1 commit into from Aug 12, 2018

Conversation

viktart
Copy link
Contributor

@viktart viktart commented Aug 11, 2018

According to Apple's documentation: activating constraints in a bunch is typically more performant than activating them one by one.

Checklist

  • I checked the Contributing Guidelines before creating this request.
  • [] New extensions are written in Swift 4.
  • New extensions support iOS 8.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+.
  • I have added tests for new extensions, and they passed.
  • All extensions have a clear comments explaining their functionality, all parameters and return type in English.
  • All extensions are declared as public.
  • I have added a changelog entry describing my changes.

@SwifterSwiftBot
Copy link

1 Warning
⚠️ Consider adding tests for new extensions or updating existing tests for a modified SwifterSwift extension
4 Messages
📖 Thank you for submitting a pull request to SwifterSwift. The team will review your submission as soon as possible.
📖 iOS: Executed 505 tests, with 0 failures (0 unexpected) in 3.003 (3.587) seconds
📖 tvOS: Executed 474 tests, with 0 failures (0 unexpected) in 1.827 (2.376) seconds
📖 macOS: Executed 336 tests, with 0 failures (0 unexpected) in 1.386 (1.706) seconds

Generated by 🚫 Danger

@codecov
Copy link

codecov bot commented Aug 11, 2018

Codecov Report

Merging #540 into master will decrease coverage by 0.03%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #540      +/-   ##
=========================================
- Coverage   93.94%   93.9%   -0.04%     
=========================================
  Files          67      67              
  Lines        2822    2823       +1     
=========================================
  Hits         2651    2651              
- Misses        171     172       +1
Flag Coverage Δ
#ios 93.9% <0%> (-0.04%) ⬇️
#osx 93.9% <0%> (+5.17%) ⬆️
#tvos 93.9% <0%> (+5.17%) ⬆️
Impacted Files Coverage Δ
Sources/Extensions/UIKit/UIViewExtensions.swift 78.07% <0%> (-0.35%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b0e512a...d29479c. Read the comment docs.

Copy link
Member

@LucianoPAlmeida LucianoPAlmeida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @viktart
What's the difference of this fillToSuperview() and the extension implemented on #539 ?

rightAnchor.constraint(equalTo: superview.rightAnchor).isActive = true
topAnchor.constraint(equalTo: superview.topAnchor).isActive = true
bottomAnchor.constraint(equalTo: superview.bottomAnchor).isActive = true
let left = leftAnchor.constraint(equalTo: superview.leftAnchor)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @viktart :))
Can you explain how this implementation is more performant that the previous?
I believe the code is more clear this way, but can't see the performance gain here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The performance gain is because you're not supposed to activate constraints individually. It's better to activate them all at once using the NSLayoutConstraint.activate API

Copy link
Member

@SD10 SD10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🥇

@SD10 SD10 merged commit 115e4a0 into SwifterSwift:master Aug 12, 2018
@@ -29,6 +29,8 @@ The changelog for **SwifterSwift**. Also see the [releases](https://github.com/S
- `removeFirst(where:)` array extension now is more generic `RangeReplaceableCollection` extensions. [#516](https://github.com/SwifterSwift/SwifterSwift/pull/516) by [LucianoPAlmeida](https://github.com/LucianoPAlmeida).
- **RandomAccessCollection**:
- `indices(of:)` array extension now is more generic `RandomAccessCollection` extensions. [#516](https://github.com/SwifterSwift/SwifterSwift/pull/516) by [LucianoPAlmeida](https://github.com/LucianoPAlmeida).
- **UIView**:
- `fillToSuperview()` should be more performant.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, post merge regret. We should clean up this CHANGELOG entry in another PR 😕 My bad guys

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, since I also approve my bad too :((
But it's simple I can fix it right :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants