Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/xdg/mime: disable fdatasync when building the XDG MIME database #62076

Merged
merged 1 commit into from May 27, 2019

Conversation

khumba
Copy link
Contributor

@khumba khumba commented May 26, 2019

Motivation for this change

Make system-path builds much faster!

Back in 2013, update-mime-database started using fdatasync() to write out
its changes after processing each file in /share/mime, with the reasoning
that a corrupted database from an interruption midway would be
problematic for applications[1]. Unfortunately, this caused a
significant regression in the time required to run update-mime-database:
commonly from under a second to half a minute or more.

This delay affects the time required to build system-path on NixOS, when
xdg.mime.enable is true (the default). For example, on one of my systems
system-path builds in ~48 seconds, 45 of which are update-mime-database.
This makes rapidly building new system configurations not fun.

This commit disables the calls to fdatasync(). update-mime-database
checks an environment variable, PKGSYSTEM_ENABLE_FSYNC, to determine
whether it should sync, and we can set this to false. system-path
already only has whatever filesystem commit guarantees that the Nix
builder provides. Furthermore, there is no risk of a failed MIME
database update messing up existing packages, because this is Nix.

(This issue was also reported at and discussed by Debian, Red Hat, and
Gentoo at least. I tried to find discussion here on Github but didn't see
anything.)

[1] https://bugs.freedesktop.org/show_bug.cgi?id=70366

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
    • I ran the installer and xdg-desktop-portal tests.
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Back in 2013, update-mime-database started using fdatasync() to write out
its changes after processing each file in /share/mime, with the reasoning
that a corrupted database from an interruption midway would be
problematic for applications[1].  Unfortunately, this caused a
significant regression in the time required to run update-mime-database:
commonly from under a second to half a minute or more.

This delay affects the time required to build system-path on NixOS, when
xdg.mime.enable is true (the default).  For example, on one of my systems
system-path builds in ~48 seconds, 45 of which are update-mime-database.
This makes rapidly building new system configurations not fun.

This commit disables the calls to fdatasync().  update-mime-database
checks an environment variable, PKGSYSTEM_ENABLE_FSYNC, to determine
whether it should sync, and we can set this to false.  system-path
already only has whatever filesystem commit guarantees that the Nix
builder provides.  Furthermore, there is no risk of a failed MIME
database update messing up existing packages, because this is Nix.

(This issue was also reported at and discussed by Debian, Red Hat, and
Gentoo at least.)

[1] https://bugs.freedesktop.org/show_bug.cgi?id=70366
Copy link
Member

@vcunat vcunat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! ❤️

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Until now I thought this slowdown was due to my slow disks!

I'll merge this, there's no reason not to.

@infinisil infinisil merged commit e383ed6 into NixOS:master May 27, 2019
@vcunat
Copy link
Member

vcunat commented May 27, 2019

Well, faster drive certainly helped, and I expect it will still make a noticeable difference after this PR :-) (say some SSD vs. 5400 rpm.)

@khumba
Copy link
Contributor Author

khumba commented May 27, 2019 via email

@infinisil
Copy link
Member

Benchmark: For my configuration, adding a new package to systemPackages was previously ~30s, whereas with this change it's only ~15s :o

@khumba khumba deleted the xdg-mime-no-sync branch May 31, 2019 01:59
@khumba
Copy link
Contributor Author

khumba commented Jun 1, 2019

A note, for posterity: one possible alternative would be to export ac_cv_func_fdatasync=no during the configure phase of shared-mime-info. This disables syncing for all invocations of update-mime-database, not only the ones that have the environment variable explicitly passed to them. This is the solution Gentoo took. It would cause quite a few rebuilds here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants