1. 15 Jun, 2018 15 commits
  2. 12 Jun, 2018 4 commits
  3. 11 Jun, 2018 3 commits
  4. 10 Jun, 2018 5 commits
  5. 09 Jun, 2018 7 commits
  6. 07 Jun, 2018 6 commits
    • Merge pull request #4576 from pks-t/pks/memory-allocator · 0ef3242e
      Custom memory allocators
      Patrick Steinhardt committed
    • settings: allow swapping out memory allocator · 74b7ddbf
      Tie in the newly created infrastructure for swapping out memory
      allocators into our settings code. A user can now simply use the new
      option "GIT_OPT_SET_ALLOCATOR" with `git_libgit2_opts`, passing in an
      already initialized allocator structure as vararg.
      Patrick Steinhardt committed
    • alloc: make memory allocators use function pointers · 9865cd16
      Currently, our memory allocators are being redirected to the correct
      implementation at compile time by simply using macros. In order to make
      them swappable at runtime, this commit reshuffles that by instead making
      use of a global "git_allocator" structure, whose pointers are set up to
      reference the allocator functions. Like this, it becomes easy to swap
      out allocators by simply setting these function pointers.
      
      In order to initialize a "git_allocator", our provided allocators
      "stdalloc" and "crtdbg" both provide an init function. This is being
      called to initialize a passed in allocator struct and set up its members
      correctly.
      
      No support is yet included to enable users of libgit2 to switch out the
      memory allocator at a global level.
      Patrick Steinhardt committed
    • stdalloc: extend allocators by file and line · 08b318c0
      Our desired architecture would make allocators completely pluggable,
      such that users of libgit2 can swap out memory allocators at runtime.
      While making e.g. debugging easier by not having to do a separate build,
      this feature can also help maintainers of bindings for libgit2 by tying
      the memory allocations into the other language's memory system.
      
      In order to do so, though, we first need to make our two different
      pre-existing allocators "stdalloc" and "crtdbg" have the same function
      signatures, as the "crtdbg" allocators all have an additional file and
      line argument. This is required to build correct stack traces for
      debugging memory allocations. As that feature may also be interesting to
      authors of other applications for debugging libgit2, we now simply add
      these arguments to our standard allocators.
      
      Obviously, this may come with a performance penalty. During some simple
      benchmarks no real impact could be measured though in contrast to a
      simple pluggable allocator. The following table summarizes the
      benchmarks. There were three different builds with our current standard
      allocator ("standard"), with pluggable authenticators accessed via
      function pointers ("pluggable") and for pluggable authenticators with
      file and line being added ("fileline"). Furthermore, there were three
      scenarios for 100.000.000 allocations of 100B ("small alloc"),
      100.000.000 allocations of 100KB ("medium alloc"), and 1.000.000
      allocations of 100MB. All results are best of 10 runs.
      
      |------------|-------------------|-------------------|-------------------|
      | build/test | small alloc       | medium alloc      | big alloc         |
      |------------|-------------------|-------------------|-------------------|
      | standard   | 4539779566, +0.0% | 5912927186, +0.0% | 5166935308, +0.0% |
      |------------|-------------------|-------------------|-------------------|
      | pluggable  | 4611074505, +1.5% | 5979185308, +1.1% | 5388776352, +4.2% |
      |------------|-------------------|-------------------|-------------------|
      | fileline   | 4588338192, +1.1% | 6004951910, +1.5% | 4942528135, -4.4% |
      |------------|-------------------|-------------------|-------------------|
      
      As can be seen, there is a performance overhead for pluggable
      allocators. Furthermore, it can also be seen that there is some big
      variance between runs, especially in the "big alloc" scenario. This is
      probably being caused by nondeterministic behaviour in the kernel for
      dynamic allocations. Still, it can be observed that there should be no
      real difference between the "pluggable" and "fileline" allocators.
      Patrick Steinhardt committed
    • util: extract allocators into its own "alloc.h" header · d2e996fa
      Our "util.h" header is a grabbag of various different functions, where
      many don't have a clear group they belong to. Our set of allocator
      functions though can be clearly singled out as a single group of
      functions that always belongs together. Furthermore, we will need to
      implement additional functions relating to our allocators subsystem when
      moving to pluggable allocators. Thus, we should just move these
      functions into their own "alloc" module.
      Patrick Steinhardt committed