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

[SR-11762] Property wrappers can cause surprising value copying #54169

Closed
BigZaphod opened this issue Nov 11, 2019 · 3 comments
Closed

[SR-11762] Property wrappers can cause surprising value copying #54169

BigZaphod opened this issue Nov 11, 2019 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself performance property wrappers Feature: property wrappers

Comments

@BigZaphod
Copy link

Previous ID SR-11762
Radar None
Original Reporter @BigZaphod
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Performance, PropertyWrappers
Assignee @theblixguy
Priority Medium

md5: 7d1996ac6ea6804b72c35b1c7acad619

Issue Description:

I have a property wrapper on an array property. For example:

@propertyWrapper
struct TestWrapper<ValueType> {
    var wrappedValue: ValueType
}
        
struct State {
    @TestWrapper
    var values: [String] = []
}

var state = State()
state.values = Array(repeating: "", count: 20000)
        
for i in 0..<20000 {
    state.values[i] = String(i)
}

Running this code is very slow (in both release and debug modes) as it causes something like 20,000 array copies to occur. If I remove the property wrapper, it runs very fast and has no array copying overhead. This is very unexpected behavior, IMO, and represents a rather nasty performance surprise when using property wrappers.

I originally posted about this on the forums here: https://forums.swift.org/t/property-wrapper-causing-excessive-array-copying/30637

Tested on Xcode 11.2.1 (11B53).

@theblixguy
Copy link
Collaborator

PR: #28216

@theblixguy
Copy link
Collaborator

Fixed on master, please verify using the next development snapshot!

@BigZaphod
Copy link
Author

Thank you!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself performance property wrappers Feature: property wrappers
Projects
None yet
Development

No branches or pull requests

2 participants