-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] properly promote stack buffer to heap buffer when necessary #20585
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
Conversation
@swift-ci please test |
@swift-ci please benchmark |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some code cleanup and testing suggestions
// Our source of code units to normalize is empty and our buffers from | ||
// previous normalizations are also empty. | ||
return nil | ||
} | ||
if segmentBufferCount == 0 && overflowBufferCount == 0 { | ||
if segmentBufferCount == 0 { | ||
//time to fill a buffer if possible. Otherwise we are done, return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't return nil anymore, do we? What's this comment describing?
|
||
expectTrue(set.contains(str)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any expectation on what this should normalize to? Can we write a test for that?
) { | ||
segmentBufferCount = count | ||
} else { | ||
segmentBufferCount = normalizeWithHeapBuffers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So along this path, we have segment input inside normalizationBuffer
, but nothing in segmentBuffer
. In the code path below, we don't have input in normalizationBuffer
. Is that important?
return segmentHeapBuffer![index] | ||
} else { | ||
let index = segmentBufferIndex | ||
segmentBufferIndex += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Common lines can be hoisted
} else { | ||
return nil | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify this code by putting the return nil
as an early return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g.:
guard segmentBufferIndex < segmentBufferCount else { return nil }
// .. now the rest of the function has less indentation and control flow
@swift-ci please test |
@swift-ci please benchmark |
Build failed |
Build failed |
} else { | ||
return nil | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g.:
guard segmentBufferIndex < segmentBufferCount else { return nil }
// .. now the rest of the function has less indentation and control flow
let strNFC = "\u{0336}\u{0308}\u{0301}\u{0357}\u{0313}\u{0314}\u{0351}\u{0300}\u{0300}\u{0300}\u{0314}\u{0357}\u{0301}\u{0308}\u{0301}\u{0315}\u{0360}\u{0061}" | ||
expectEqual(str, strNFC) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to test the case where the previous approach would've skipped over the long segment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this new test caught it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The concern was that a corner case would cause us to skip a portion of the String. Unfortunately, a test case expressed in terms of string comparison is only testing behavioral consistency but not the actual result. We have _nfcCodeUnits
and _withNFCCodeUnits
to check exactly this.
Build comment file:Performance: -O
Performance: -Osize
Performance: -Onone
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
@swift-ci please test |
@swift-ci please benchmark |
Build failed |
Build failed |
Build comment file:Performance: -Onone
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
a29b111
to
fc3341e
Compare
@swift-ci please test |
Build failed |
@swift-ci please benchmark |
@swift-ci please test |
@swift-ci please benchmark |
Approved with request for follow PR that tests the actual normalized code units rather than String comparison |
Build failed |
Build comment file:Performance: -Osize
Performance: -Onone
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
@swift-ci please test Linux platform |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
rdar://problem/45216800
https://bugs.swift.org/browse/SR-8939