<div dir="ltr"><div><div>Hi,<br><br>I just created a new PR #7557 (<a href="https://github.com/apple/swift/pull/7557">https://github.com/apple/swift/pull/7557</a>) which replaces #7421.<br><br></div>Thanks,<br>-- Mikio<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-02-17 13:03 GMT+09:00 Slava Pestov via swift-dev <span dir="ltr"><<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Feb 16, 2017, at 6:48 PM, Jiho Choi via swift-dev <<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>> wrote:</div><br class="m_-1359470046744239486Apple-interchange-newline"><div><div dir="ltr">Hi,<div><br></div><div>I was curious about the overhead of ARC and started profiling some benchmarks found in the Computer Language Benchmark Game (<a href="http://benchmarksgame.alioth.debian.org/u64q/measurements.php?lang=swift" target="_blank">http://benchmarksgame.alioth.<wbr>debian.org/u64q/measurements.<wbr>php?lang=swift</a>). So far, it seems that ARC sequence optimization is surprisingly good and most benchmarks don't have to perform ARC operations as often as I expected. I have some questions regarding this finding.</div><div><br></div><div>I compiled all benchmarks with "-O -wmo" flags and counted the number of calls to ARC runtime (e.g., swift_rt_swift_retain) using Pin.</div><div><br></div><div>1. Reference counting is considered to have high overhead due to frequent counting operations which also have to be atomic. At least for the benchmarks I tested, it is not the case and there is almost no overhead. Is it expected behavior? Or is it because the benchmarks are too simple (they are all single-file programs)? How do you estimate the overhead of ARC would be?</div></div></div></blockquote><div><br></div></span>It is possible that the optimizer eliminated many reference counting operations here. Also my understanding is that while atomic operations are more expensive than non-atomic operations, the real cost only comes into play if you actually have contention due to bouncing cache lines. In a single-threaded workload the overhead is not that great.</div><div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>2. I also tried to compile the same benchmarks with "-Xfrontend -assume-single-threaded" to measure the overhead of atomic operations. Looking at the source code of this experimental pass and SIL optimizer's statistic, the pass seems to work as expected to convert all ARC operations in user code into nonatomic. However, even when using this flag, there are some atomic ARC runtime called from the user code (not library). More strangely, SIL output said all ARC operations in the user code have turned into nonatomic. The documentation says ARC operations are never implicit in SIL. So if there is no atomic ARC at SIL-level, I expect the user code would never call atomic ARC runtime. Am I missing something?</div></div></div></blockquote><div><br></div></span>IRGen still emits atomic reference counting operations when it produces value witness operations. I think there’s a PR open right now to address this: <a href="https://github.com/apple/swift/pull/7421" target="_blank">https://github.com/<wbr>apple/swift/pull/7421</a></div><div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>3. Are there more realistic benchmarks available? Swift's official benchmarks also seem pretty small.</div></div></div></blockquote><div><br></div></span>Contributions are welcome :-)</div><div><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>Thanks,</div><div>Jiho</div></div>
______________________________<wbr>_________________<br>swift-dev mailing list<br><a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-dev" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-dev</a><br></div></blockquote></div><br></div><br>______________________________<wbr>_________________<br>
swift-dev mailing list<br>
<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-dev</a><br>
<br></blockquote></div><br></div>