aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
AgeCommit message (Collapse)Author
2022-02-28Merge remote-tracking branch 'upstream/master' into auto-uid-allocationJohn Ericson
2022-02-25Remove std::string alias (for real this time)Eelco Dolstra
Also use std::string_view in a few more places.
2022-02-25xml-writer: Remove std aliasesEelco Dolstra
2022-02-21Remove std::string aliasEelco Dolstra
2022-02-21Remove std::vector aliasEelco Dolstra
2022-02-21Remove std::set aliasEelco Dolstra
2022-02-21Remove std::list aliasEelco Dolstra
2022-02-21Merge pull request #6052 from ↵Eelco Dolstra
hercules-ci/issue-3294-fix-interruptCallback-deadlock Fix deadlocked nix-daemon zombies on darwin #3294
2022-02-21triggerInterrupt: Refactor to use breakRobert Hensing
2022-02-07Make sure no exceptions leave ignoreException()Sergei Trofimovich
I noticed that occasional Ctrl-C leaves *.lock files around. `nix-daemon`'s journal logs contained crashes like: nix-daemon[30416]: terminate called after throwing an instance of 'nix::SysError' nix-daemon[30416]: what(): error: writing to file: Broken pipe And core dump backtraces pointed at `teriminate()` call from destructors: ... _Unwind_Resume () nix::ignoreException() () nix::LocalDerivationGoal::~LocalDerivationGoal() ... void ignoreException() { try { throw; } catch (std::exception & e) { printError("error (ignored): %1%", e.what()); } } The crashes happen when client side closes early and printError() throws an IO error. The change wraps `ignoreException()` into blanket `try { ... } catch (...) {}`. Closes: https://github.com/NixOS/nix/issues/6046
2022-02-06Don't hold interruptCallbacks lock during interrupt handlingRobert Hensing
This changes the representation of the interrupt callback list to be safe to use during interrupt handling. Holding a lock while executing arbitrary functions is something to avoid in general, because of the risk of deadlock. Such a deadlock occurs in https://github.com/NixOS/nix/issues/3294 where ~CurlDownloader tries to deregister its interrupt callback. This happens during what seems to be a triggerInterrupt() by the daemon connection's MonitorFdHup thread. This bit I can not confirm based on the stack trace though; it's based on reading the code, so no absolute certainty, but a smoking gun nonetheless.
2022-02-02Merge branch 'more-stringviews' of https://github.com/pennae/nixEelco Dolstra
2022-01-29canonPath: fix missing slash when resolving linksWill Dietz
Fixes #6017
2022-01-27optionally return string_view from coerceToStringpennae
we'll retain the old coerceToString interface that returns a string, but callers that don't need the returned value to outlive the Value it came from can save copies by using the new interface instead. for values that weren't stringy we'll pass a new buffer argument that'll be used for storage and shouldn't be inspected.
2022-01-27return string_views from forceString*pennae
once a string has been forced we already have dynamic storage allocated for it, so we can easily reuse that storage instead of copying.
2022-01-27convert a for more utilities to string_viewpennae
2022-01-25Remove unused Rust stuffEelco Dolstra
In particular we were still compiling rust-ffi.cc even though we're not using it.
2022-01-24hiliteMatches(): Style fixes, pass more stuff by referenceEelco Dolstra
2022-01-24Add a small documentation for `hiliteMatches`regnat
2022-01-21Add some tests for hiliteMatches in libutilFishhh
2022-01-21Move hilite_all into libutil and rename it to hiliteMatchesFishhh
The signature was also changed so the function now accepts a vector instead of an iterator
2022-01-18Merge pull request #5906 from pennae/primops-optimizationEelco Dolstra
optimize primops and utils by caching more and copying less
2022-01-18Merge pull request #5932 from edolstra/remove-shared-stringsEelco Dolstra
Remove shared strings
2022-01-18Get rid of std::shared_ptr<std::string> and ref<std::string>Eelco Dolstra
These were needed back in the pre-C++11 era because we didn't have move semantics. But now we do.
2022-01-17StringSource: Use std::string_viewEelco Dolstra
2022-01-17serialise.hh: Use std::string_viewEelco Dolstra
2022-01-17Merge pull request #5812 from pennae/small-perf-improvementsEelco Dolstra
improve parser performance a bit
2022-01-13avoid copies of parser input datapennae
when given a string yacc will copy the entire input to a newly allocated location so that it can add a second terminating NUL byte. since the parser is a very internal thing to EvalState we can ensure that having two terminating NUL bytes is always possible without copying, and have the parser itself merely check that the expected NULs are present. # before Benchmark 1: nix search --offline nixpkgs hello Time (mean ± σ): 572.4 ms ± 2.3 ms [User: 563.4 ms, System: 8.6 ms] Range (min … max): 566.9 ms … 579.1 ms 50 runs Benchmark 2: nix eval -f ../nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix Time (mean ± σ): 381.7 ms ± 1.0 ms [User: 348.3 ms, System: 33.1 ms] Range (min … max): 380.2 ms … 387.7 ms 50 runs Benchmark 3: nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system' Time (mean ± σ): 2.936 s ± 0.005 s [User: 2.715 s, System: 0.221 s] Range (min … max): 2.923 s … 2.946 s 50 runs # after Benchmark 1: nix search --offline nixpkgs hello Time (mean ± σ): 571.7 ms ± 2.4 ms [User: 563.3 ms, System: 8.0 ms] Range (min … max): 566.7 ms … 579.7 ms 50 runs Benchmark 2: nix eval -f ../nixpkgs/pkgs/development/haskell-modules/hackage-packages.nix Time (mean ± σ): 376.6 ms ± 1.0 ms [User: 345.8 ms, System: 30.5 ms] Range (min … max): 374.5 ms … 379.1 ms 50 runs Benchmark 3: nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system' Time (mean ± σ): 2.922 s ± 0.006 s [User: 2.707 s, System: 0.215 s] Range (min … max): 2.906 s … 2.934 s 50 runs
2022-01-13use more string_view in utilspennae
there's a couple places that can be easily converted from using strings to using string_views instead. gives a slight (~1%) boost to system eval. # before nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system' Time (mean ± σ): 2.946 s ± 0.026 s [User: 2.655 s, System: 0.209 s] Range (min … max): 2.905 s … 2.995 s 20 runs # after Time (mean ± σ): 2.928 s ± 0.024 s [User: 2.638 s, System: 0.211 s] Range (min … max): 2.893 s … 2.970 s 20 runs
2022-01-12Merge pull request #5887 from pennae/avoid-streamsThéophane Hufschmitt
avoid std::?stream overhead when it's not helpful
2022-01-12use boost::lexical_cast for string2*pennae
this avoids one copy from `s` into `str`, and possibly another copy needed to construct `s` at the call site. lexical_cast is also more efficient in general.
2022-01-11Merge pull request #5898 from layus/repair-path-linksEelco Dolstra
Make --repair-path also repair corrupt optimised links
2022-01-11Make --repair-path also repair corrupt optimised linksGuillaume Maudoux
There already existed a smoke test for the link content length, but it appears that there exists some corruptions pernicious enough to replace the file content with zeros, and keeping the same length. --repair-path now goes as far as checking the content of the link, making it true to its name and actually repairing the path for such coruption cases.
2022-01-07dump(): Use emplace()Eelco Dolstra
2022-01-07isInDir() / isDirOrInDir(): Use std::string_viewEelco Dolstra
2022-01-07avoid ostream sentries per json string characterpennae
we don't have to create an ostream sentry object for every character of a JSON string we write. format a bunch of characters and flush them to the stream all at once instead. this doesn't affect small numbers of string characters, but larger numbers of total JSON string characters written gain a lot. at 1MB of total string written we gain almost 30%, at 16MB it's almost a factor of 3x. large numbers of JSON string characters do occur naturally in a nixos system evaluation to generate documentation (though this is now somewhat mitigated by caching the largest part of nixos option docs). benchmarked with hyperfine 'nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) {e})"' --warmup 1 -L e 1,4,256,4096,65536 before: Benchmark 1: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 1)" Time (mean ± σ): 12.5 ms ± 0.2 ms [User: 9.2 ms, System: 4.0 ms] Range (min … max): 11.9 ms … 13.1 ms 223 runs Benchmark 2: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 4)" Time (mean ± σ): 12.5 ms ± 0.2 ms [User: 9.3 ms, System: 3.8 ms] Range (min … max): 11.9 ms … 13.2 ms 220 runs Benchmark 3: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 256)" Time (mean ± σ): 13.2 ms ± 0.3 ms [User: 9.8 ms, System: 4.0 ms] Range (min … max): 12.6 ms … 14.3 ms 205 runs Benchmark 4: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 4096)" Time (mean ± σ): 24.0 ms ± 0.4 ms [User: 19.4 ms, System: 5.2 ms] Range (min … max): 22.7 ms … 25.8 ms 119 runs Benchmark 5: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 65536)" Time (mean ± σ): 196.0 ms ± 3.7 ms [User: 171.2 ms, System: 25.8 ms] Range (min … max): 190.6 ms … 201.5 ms 14 runs after: Benchmark 1: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 1)" Time (mean ± σ): 12.4 ms ± 0.3 ms [User: 9.1 ms, System: 4.0 ms] Range (min … max): 11.7 ms … 13.3 ms 204 runs Benchmark 2: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 4)" Time (mean ± σ): 12.4 ms ± 0.2 ms [User: 9.2 ms, System: 3.9 ms] Range (min … max): 11.8 ms … 13.0 ms 214 runs Benchmark 3: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 256)" Time (mean ± σ): 12.6 ms ± 0.2 ms [User: 9.5 ms, System: 3.8 ms] Range (min … max): 12.1 ms … 13.3 ms 209 runs Benchmark 4: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 4096)" Time (mean ± σ): 15.9 ms ± 0.2 ms [User: 11.4 ms, System: 5.1 ms] Range (min … max): 15.2 ms … 16.4 ms 171 runs Benchmark 5: nix eval --raw --expr "let s = __concatStringsSep \"\" (__genList (_: \"c\") 256); in __toJSON (__genList (_: s) 65536)" Time (mean ± σ): 69.0 ms ± 0.9 ms [User: 44.3 ms, System: 25.3 ms] Range (min … max): 67.2 ms … 70.9 ms 42 runs
2021-12-28BaseError::calcWhat: take loggerSettings.showTrace into accountAlexander Bantyev
Text representation for errors should include the trace if --show-trace is passed.
2021-12-22Merge pull request #5821 from edolstra/remove-affinityEelco Dolstra
Remove CPU locking
2021-12-22Don't insert spaces when completing attribute pathsNaïm Favier
2021-12-22Remove CPU lockingEelco Dolstra
This was already accidentally disabled in ba87b08. It also no longer appears to be beneficial, and in fact slow things down, e.g. when evaluating a NixOS system configuration: elapsed time: median = 3.8170 mean = 3.8202 stddev = 0.0195 min = 3.7894 max = 3.8600 [rejected, p=0.00000, Δ=0.36929±0.02513]
2021-12-16Ignore EPERM when unsharing FS stateEelco Dolstra
On Docker (but not podman), unshare(CLONE_FS) fails with EPERM. So let's ignore it and hope nothing bad happens. Attempted fix for #5777.
2021-12-14Merge pull request #5702 from baloo/baloo/hide-non-reproducible-settingsThéophane Hufschmitt
reproducibility: hide non-reproducible settings from manual
2021-12-10extract_archive: fix "Hard-link target '...'" errorYorick van Pelt
Fixes #5741
2021-12-10extract_archive: use copy_pathname instead of set_pathname.Yorick van Pelt
Libarchive documentation mentions that archive_entry_set_pathname expects us to keep the passed string alive, which we don't.
2021-12-09Merge pull request #5695 from obsidiansystems/tidy-loggingEelco Dolstra
Tidy up the logging
2021-12-01src/libutil/util.hh: fix build on gcc-11Sergei Trofimovich
Due to missing <atomic> declaration the build fails as: src/libutil/util.hh:350:24: error: no match for 'operator||' (operand types are 'std::atomic<bool>' and 'bool') 350 | if (_isInterrupted || (interruptCheck && interruptCheck())) | ~~~~~~~~~~~~~~ ^~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | std::atomic<bool> bool
2021-12-01reproducibility: hide non-reproducible settings from manualArthur Gautier
Because the manual is generated from default values which are themselves generated from various sources (cpuid, bios settings (kvm), number of cores). This commit hides non-reproducible settings from the manual output.
2021-11-30Tidy up the loggingJohn Ericson
Use the macros more, so we properly skip work when the log level excludes. Also log the daemon operation number on the daemon side.
2021-11-29createTempFile(): Mark file as CLOEEXECEelco Dolstra
Fixes #5674.
2021-11-24Fix a minor data race with _isInterruptedAlex Shabalin