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

Reduce dynamic casts #805

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ChrisBenua
Copy link

@ChrisBenua ChrisBenua commented Apr 1, 2024

Description

This pull requests replaces dynamicCasts (as?) with protocol method calls

Motivation

In our company we heavily rely on SnapKit. So my team and I have investigated SnapKit performance in extremely-large apps. We discovered that dynamicCasts have significant performance impact on SnapKit performance: about 5/6 of time taken by Constraint.init (and its call-tree) is occupied by dynamic_cast_existential_1_conditional. All measurements were made by opening the most important and visited screens in our iOS app.

Before optimisations:

SnapKit-Before

After optimisations:
SnapKit-After

Changes Made

Extended some protocols with new methods that are used to avoid using as?.
Also, we've successfully avoided breaking ABI (at least in our project).

This Pull Request doesn't require to change call site: ConstraintItem.init is internal and I doubt that somebody has class or struct conforming to ConstraintConstantTarget, ConstraintDSL, ConstraintRelatableTarget or ConstraintInsetTarget.

Testing Done

  • Compiled for iOS and macOS
  • Checked basic layout in Example app
  • Checked complex layouts in our app
  • Ran unit-tests locally

Please review this pull request and provide feedback. Thanks in advance!

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

1 participant