9 ms·
Is mmap still faster than fread? That might have been true in the 90s but I was wondering about current improvements. If you have enough free memory, the file
by habibur 1y ago
Is mmap still faster than fread? That might have been true in the 90s but I was wondering about current improvements.
If you have enough free memory, the file will be cached in memory anyway instead of residing on disk. Therefore both will be reading from memory, albeit through different API.
Looking for recent benchmark or view from OS developers.
- stingraycharles 1y agoIn our experience building a high performance database server: absolutely. If your line of thinking is “if you have enough free memory”, then these types of optimizations aren’t for you. one of the main benefits is eliminating an extra copy. additionally, mmap is heavily optimized for random access, so if that’s what you’re doing, then you’ll have a much better time with it than fread. (I hope a plug is not frowned upon here: if you like this kind of stuff, we’re a fully remote company and hiring C++ devs: https://apply.workable.com/quasar/j/436B0BEE43/ https://apply.workable.com/quasar/j/436B0BEE43/ )
- YouAreWRONGtoo 1y ago[flagged]
- vlovich123 1y agoWhat’s the false advertising?
- deaddodo 1y agoYeah, I took a look at the posting and it’s a bog standard job posting. I assume they’re referring to the no-salary aspect and (based on their speech style) are in the US. But, even in that case, it would only matter if the posting were targeted to one of the states that require salary information and the company operated or had a presence in said state. Since it’s an EU company, that’s almost definitely not the case.
- vlovich123 1y ago> and the company operated or had a presence in said state And the company was big enough. AFAIK the salary transparency stuff only applies when your headcount exceeds some number.
- YouAreWRONGtoo 1y ago[dead]
- jasonwatkinspdx 1y agoI'd be shocked if anyone would hire you after seeing this behavior...
- YouAreWRONGtoo 1y ago[dead]
- do_not_redeem 1y agoEven if the file is cached, fread has to do a memcpy. mmap doesn't.
- gpderetta 1y agofread is (usually) buffered io, so it actually does two additional mem copies (kernel to FILE buffer then to user buffer)
- assbuttbuttass 1y agoNot in Go
- gpderetta 1y agooh, right, this is Go (https://pkg.go.dev/github.com/odeke-em/go-utils/fread#section-readme https://pkg.go.dev/github.com/odeke-em/go-utils/fread#sectio...). Do the strings it return share memory with the internal buffer?
- loeg 1y agoread, or fread? fread is the buffered version that does an extra copy for no reason that would benefit this use case.