!VRULIdgoKmKPzJZzjj:nixos.org

Nix Package Manager development

858 Members
For people hacking on Nix: https://github.com/NixOS/nix Nix maintainers can be reached here.184 Servers

Load older messages


SenderMessageTime
21 Oct 2025
@niksnut:matrix.orgEelco learned today that using std::string for large buffers is very inefficient (huge kernel overhead): https://github.com/DeterminateSystems/nix-src/pull/238/commits/edf45d6e1158a059e7ded5460d2a3947dc35fdf8 20:44:48
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)This is sort of more about doing unnecessary construction/destruction of an object. Not special to std::string in any way20:55:40
@niksnut:matrix.orgEelcoit's a result of having a large contiguous allocation (so it would also affect std::vector<char>)20:56:21
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)Yeah, it's much better to allocate once and reuse that allocation as you did there20:56:45
@niksnut:matrix.orgEelcoa data type that consists of a vector of buffers would avoid this problem20:57:06
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)I did a similar cleanup in filetransfer..cc at some point20:57:07
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)You'd still benefit from allocating it only once though20:57:23
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)Going through malloc/free is still a function call through PLT and doing that in a loop is kind of expensive anyway20:58:05
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)https://llvm.org/docs/ProgrammersManual.html#vector20:58:58
@niksnut:matrix.orgEelcoit's funny though that the optimization that skipped parsing 15 GB of NARs (https://github.com/DeterminateSystems/nix-src/pull/238/commits/1f8d587a0df8f9de366640831dade43d17021c30) had basically no observable effect21:01:55
@niksnut:matrix.orgEelcoit's completely dwarfed by the memory allocation / page fault overhead21:02:07
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)Yeah that will do it certainly. Also having a too large buffer on the stack is bad: https://github.com/NixOS/nix/pull/1387721:03:27
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)The stack pointer does get decremented one page at a time. Is that the default behavior or some hardening flag?21:04:10
@niksnut:matrix.orgEelcosurprising since stack pages should stay around once paged in21:07:22
@niksnut:matrix.orgEelcothough there is some overhead to handle guard pages21:07:42
@niksnut:matrix.orgEelcoso it has to touch at least 1 byte every 4096 bytes21:07:52
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)Yeah that was the overhead. A loop over all the pages21:08:28
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)
   1.23 │       lea    -0x10000(%rsp),%r11
   0.23 │ 15:   sub    $0x1000,%rsp
   1.01 │       orq    $0x0,(%rsp)
  59.12 │       cmp    %r11,%rsp
   0.27 │     ↑ jne    15
21:08:42
@niksnut:matrix.orgEelcoright, that's to avoid a segfault if you have guard pages enabled (which I think is the default)21:09:13
@niksnut:matrix.orgEelcoI would expect the overhead for that loop to be pretty trivial though21:09:31
@niksnut:matrix.orgEelcoin the case where the pages are present21:09:52
22 Oct 2025
@0xcafca:matrix.org0xcafca changed their profile picture.10:21:53
@0xcafca:matrix.org0xcafca changed their profile picture.10:23:31
@tomberek:matrix.orgtomberek @niksnut:matrix.org: builtins.fetchTree cannot take advantage of the "__final" optimization. This means usages of flake-compat will re-fetch inputs unnecessarily. Is there a way to expose `prim_fetchFinalTree`. This can create a large performance regression. 15:11:06
@niksnut:matrix.orgEelco I think we should allow fetchTree { final = true; ... } 15:11:43
@roberthensing:matrix.orgRobert Hensing (roberth) I get what it does but I never felt like I had a complete understanding somehow. If we were wrong about final we could always design something better without the pressure and call it fetchSource :) 15:14:03
@niksnut:matrix.orgEelco final just means it won't add more attributes 15:17:39
@tomberek:matrix.orgtomberek @roberthensing:matrix.org: is the concern that it would be abused ir ossify some behavior? 15:26:18
@roberthensing:matrix.orgRobert Hensing (roberth)I guess I just expected it to be prettier15:26:44
@roberthensing:matrix.orgRobert Hensing (roberth)sometimes things just aren't, and that's ok15:27:35

Show newer messages


Back to Room ListRoom Version: 6