CBinding.jl icon indicating copy to clipboard operation
CBinding.jl copied to clipboard

Long time initialization of CBinding

Open foxtran opened this issue 3 years ago • 1 comments

I have two versions of Julia and CBinding. All tests are done under Ubuntu 20.04, WSL2, Intel(R) Core(TM) i9-10940X CPU @ 3.30GHz.

There are two scripts that have close definitions.

  1. CBinding 0.9.4:
using CBinding

@cstruct {
      x::Int64
      y::Int64
}
  1. CBinding 1.0.9:
using CBinding

c``

c"""
#include <stdint.h>
"""s;

c"""
  struct Point {
      int64_t x;
      int64_t y;
  };
"""j;

Timing (real) of running of some configurations. I got these value by running time julia-ver script.jl

Julia 1.4.1 + CBinding 0.9.4 Julia 1.7.3 + CBinding 0.9.4 Julia 1.7.3 + CBinding 1.0.9
0m1.239s 0m0.948s 0m6.744s
0m1.203s 0m0.989s 0m6.672s
0m1.197s 0m0.972s 0m6.731s
0m1.159s 0m1.027s 0m6.653s
0m1.227s 0m0.987s 0m6.756s

The fastest version of CBinding is 0.9.4 with Julia 1.7.3. The current release is >6 times slower. Is it possible to speed up the upcoming releases?

foxtran avatar May 26 '22 09:05 foxtran

This appears to be due to Julia compilation on the first time c"..." macro is encountered.

@time @eval using CBinding
@time @eval c``
@time @eval c"""
  struct Point1 {
      long long x;
      long long y;
  };
"""j;
@time @eval c"""
  struct Point2 {
      long long x;
      long long y;
  };
"""j;
$ time julia-ver init-time.jl 
  0.127416 seconds (366.37 k allocations: 23.747 MiB, 23.11% compilation time)
  1.036880 seconds (3.39 M allocations: 204.519 MiB, 3.83% gc time, 2.10% compilation time)
  4.584189 seconds (15.00 M allocations: 879.728 MiB, 7.24% gc time, 99.91% compilation time)
  0.013201 seconds (9.30 k allocations: 347.551 KiB, 20.69% compilation time)

real    0m5.933s
user    0m5.953s
sys     0m0.467s

Since CBinding is using CBinding-generated bindings to interface libclang, this is most likely a manifestation of #98, and is definitely something that can be improved.

krrutkow avatar May 26 '22 13:05 krrutkow