[flang-dev] FW: Performance of std::remove_if in F18 file I/O

Richard Barton via flang-dev flang-dev at lists.llvm.org
Thu Apr 2 12:10:29 PDT 2020



-----Original Message-----
From: Peter Klausler <pklausler at nvidia.com> 
Sent: 2 April, 2020 19:15
To: Richard Barton <Richard.Barton at arm.com>
Subject: RE: Performance of std::remove_if in F18 file I/O

The simple loop is not in the benchmark because it was expected to be slow.  It is a sanity check on a compiler's ability to optimize remove_if with good inlining to reduce the remove_if instantiation down to something like the simple loop.  If remove_if is somehow *faster* than the simple loop, then I would question the validity of the experiment.

-----Original Message-----
From: Richard Barton <Richard.Barton at arm.com> 
Sent: Thursday, April 2, 2020 10:31 AM
To: flang-dev at lists.llvm.org
Cc: Peter Klausler <pklausler at nvidia.com>; David Truby <David.Truby at arm.com>
Subject: Performance of std::remove_if in F18 file I/O

External email: Use caution opening links or attachments


Hi flang-dev

During the code review on the patch to switch F18's file handling code from using C library to C++ library routines [1] we hit upon a case that seemed to show the C++ std::remove_if routine was much slower than the C routine on some platforms. The routine in question is RemoveCarriageReturns in lib/Parser/source.cpp [2] and existing findings are at [3][4][5]. We are seeing quite different performance numbers across different platforms.

Peter Klausler made a little performance harness around the two proposed implementations  and a third naïve implementation that we would expect to be the slowest (for reference rather than proposed for use in F18). I have attached this harness, with a few NFC modifications to this email.

Is anyone able to give this a run on their system and report their results? Please enable optimisation whilst compiling as this will match the F18 configuration we most care about. Please include the compiler and C & C++ standard library versions used as well as the architecture and platform. We've not tried this at all on Windows, so we'd be interested if anyone can provide that info.

The implementation using std::remove_if is preferred on LLVM-like style grounds so we would like to make this change. However, we don't want to significantly regress the performance of F18 file reading while we do that. We'd like to make the change but only if the new code is in the same performance ballpark as the existing code.

Thanks
Rich

[1] https://github.com/flang-compiler/f18/pull/1032
[2] https://github.com/flang-compiler/f18/blob/96c6be633ff65ec6d84c18e0d14393137d8097dd/lib/Parser/source.cpp#L73
[3] https://github.com/flang-compiler/f18/pull/1032#discussion_r391846621
[4] https://github.com/flang-compiler/f18/pull/1032#discussion_r392125932
[5] https://github.com/flang-compiler/f18/pull/1032#discussion_r392311031
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------


More information about the flang-dev mailing list