Giter VIP home page Giter VIP logo

build-go-cache's Introduction

buildGoCache

buildGoCache speeds up nix's buildGoModule by pre-compiling imported go modules

Potential speed-up

For telegraf we measured the following build times with and without the buildGoCache.

Build machine: AMD Ryzen 9 7950X3D 16-Core Processor, 128G DDR4 RAM, zfs raid0

without cache:

time nix build .#example-no-cache -L
0.28s user 0.20s system 0% cpu 59.539 total
time nix build .#example-proxy-vendor-no-cachA
0.30s user 0.20s system 0% cpu 1:14.01 total

with cache:

time nix build .#example -L
0.23s user 0.18s system 1% cpu 25.872 total
time nix build .#example-proxy-vendor -L
0.03s user 0.04s system 0% cpu 30.501 total

Speedup: 2.3x..~2.4x

Usage

First we generate a list of all imported packages:

nix run .#get-external-imports -- ./. imported-packages

Than we modify our buildGoModule to use your go build cache:

let
  vendorHash = "sha256-aMO7nH68E1S5G1iWj29McK0VY0frfjNnJ6D6rJ29cqQ=";
  proxyVendor = true; # must be in sync for buildGoCache and buildGoModule
  src = ./.; # replace this with the source directory

  goCache = buildGoCache {
    importPackagesFile = ./imported-packages;
    inherit src vendorHash proxyVendor;
  };
in
buildGoModule {
  name = "myproject";

  buildInputs = [ goCache ];

  inherit src;

  inherit vendorHash proxyVendor;
}

See ./examples for real-world examples based on telegraf and gomod2nix

Other real-world example

build-go-cache's People

Contributors

cbrewster avatar mic92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

cbrewster

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.