5 ms·
As someone who writes portable high-performance C++ code for living I see this as no more than a great prototyping aid. Adding a non-trivial system abstraction
by huhtenberg 12y ago
As someone who writes portable high-performance C++ code for living I see this as no more than a great prototyping aid.
Adding a non-trivial system abstraction to your code - be it a file system or a socket/networking API - is always a tricky task, even for the simplest of requirements. For example, Windows API is inherently UTF16, so if you want good performance, you need to keep all your filesys references in wstirngs. But not on Windows, you'll need strings instead. If you are to abstract this, you have a choice of either using an opaque "filesystem_string" type that maps to wstring/string (with an API for cross-conversion) or defining, say, an UTF8 API and then doing a boatload of run-time Unicode conversion on Windows. The fun part is that while this makes the filesystem code more compact, it has a negative effect on the rest of the application. The app will either need to deal with conversions to/from "filesystem_string" when serializing/displaying them or the abstraction layer will be busy converting utf8's to the native string format. Either way you pay with performance for "portability".
This doesn't apply to just this new C++ TS. It's the same issue with the existing standard POSIX API as well (fopen/fread/etc). It's great for hacking together something that builds on Linux, BSD and Windows, but you'd typically want to put in your own system interface before shipping production version.
- aristidb 12y agoI think for most programs, path manipulation is fortunately not in the performance-critical parts.
- tedunangst 12y agoThere's always that one exception... http://lists.gnu.org/archive/html/coreutils/2014-08/msg00012.html http://lists.gnu.org/archive/html/coreutils/2014-08/msg00012...
- calvins 12y agoThat's not about path manipulation. It's about resizing the hash table that is required for keeping track of hard links when copying hundreds of millions of files using cp. The path manipulation that cp does would still be inconsequential in that example.
- roel_v 12y ago" so if you want good performance, you need to keep all your filesys references in wstirngs." Why? For path manipulation, you can still use whatever format internally that you want. Only just before the native API calls you'll need to convert. I'm open to many arguments on performance, but I have a hard time believing that this conversion would matter (or even be measurable) relative to the time the actual I/O will take. Filesystem is a great addition to the C++ standard library. If you're seriously claiming that filesystem will not be suitable for production code, I can't help but put you in the (hypothetical) group of people who say 'the standard allocator is only a great prototyping aid, you'd typically want to put in your own allocator before shipping production version.'. Uh no, millions of application ship just fine with the standard allocator, just like thousands (or maybe even hundreds of thousands) of applications are already shipping just fine with boost filesystem.
- MaulingMonkey 12y ago>> " so if you want good performance, you need to keep all your filesys references in wstirngs." > Why? I'd take this even further: The less (re)interpretation the better. Will my UTF16 <-> UTF8 conversion roundtrip my malformed UTF16 codepoints? If not, I've just lost compatibility with (admittedly buggy) software. But I've seen bugs from far tamer, such as from the simple act of converting from a fixed width wchar_t[] that was observed to be a NUL terminated UTF16 string to std::wstring. It turned out that under certain circumstances that couldn't be tested, it was an opaque binary blob with NULs in the middle... and the bit after the NULs being important. Whoops! Less relevant here though: std::experimental::filesystem::v1::path::value_type looks to match the native OS character type. But then again, is that unichar (16-bit) or wchar_t (32-bit) on iOS? Fufufufu~ It's also just plain easier when you're dealing with native filesystem APIs for whatever reason to work in the native character type, which is the main reason I'd prefer it. > but I have a hard time believing that this conversion would matter (or even be measurable) relative to the time the actual I/O will take. RE: Performance: If you're doing actual I/O, agreed. If you're dealing with OS or application cached filesystem entries, it becomes more believable. If you're enumerating over and only conditionally performing I/O over hundreds of thousands of paths - you'll want to be quite cautious of conversions if you care about performance (potentially see: directory enumeration via backups, stale file scans during builds, or comparing file lists between VCS revisions...) It drives me absolutely insane when a 'nothing changed' build takes 10, 20 seconds just from filesystem scanning. And I've seen and fixed far worse (think O(n*n) scans -_-;;). As others have noted though, if you keep your conversions 'reasonable' you should be able to get away with UTF8 paths from a performance perspective. > Filesystem is a great addition to the C++ standard library. Agreed.
- gilgoomesh 12y agoUTF8/UTF16 conversions are far cheaper than you think they are. Especially when compared to the cost of a GetFileAttributesExW or other filesystem operation. I use boost::filesystem for a server that performs large numbers of bulk file system traversals. I keep all my pathnames in UTF-8 and make boost::filesystem perform all the conversions (you need to imbue the boost::filesystem locale with a UTF-8 conversion facet to force UTF-8 on Windows but that's straightforward). When reading from NTFS cached data, the overhead of UTF-8 to UTF-16 conversions is around 15% in the worst case of ~300 char Long Path operations and much less for smaller paths or uncached data. If 15% overhead is going to kill your performance then yes, avoid the standard library and write your own classes; that's probably true for all standard library classes. For all other cases, you'd be foolish to write everything yourself.
- blt 12y agoMaybe true for filesystem-heavy applications, but many C++ programs only need to do something simple like load a small directory of plugins. this lib will be perfect for stuff like that.
- sjolsen 12y ago> It's the same issue with the existing standard POSIX API It's only an "issue" if you look at this as being an attempt to create a be-all end-all API, and it isn't. Things like std::filesystem (and POSIX file APIs) are made not to replace the native APIs but to complement them. They exist to fill the need for cheap, simple auxiliary tools, not the need for high-performance tools. In other words, std::filesystem doesn't exist to facilitate writing a high-performance whole-filesystem search engine. It exists to facilitate writing high-performance audio analysis tools, image manipulation libraries, funky customizable desktop widgets, or really any conceivable program which uses the filesystem, but never in a hot loop. It exists for the same reason std::string exists in spite of the fact that it would a terrible core data structure for a text editor. It exists for the same reason std::iostream exists even though you would have to be insane to try to write an HTTP engine with it. It exists because when you need to load up three 200-megabyte files to grab the input for an hour-long simulation, you don't care about an extra five milliseconds at startup as much as you care about dead-simple, reliable code. Or maybe you do, in which case you can still happily use the native API.