CBinding.jl
CBinding.jl copied to clipboard
Long compilation time for large Carrays
It takes a lot of time to instantiate a parsed struct with very large char arrays.
Minimal example
# example.jl
using CBinding;
c`
-Wall
-Werror
`
c"""
/* Default size on my system according to my <stdio.h>. */
# define BUFSIZ 8192
struct example_t {
char dummy[BUFSIZ];
};
"""
example = c"struct example_t"r(dummy = "example");
0; # supress large output in the REPL
It takes nearly 3 Minutes and a lots of RAM (it seems):
julia> @time include("example.jl") # first call
165.834280 seconds (39.78 M allocations: 8.739 GiB, 1.16% gc time, 99.91% compilation time)
julia> @time include("example.jl") # second call
127.044148 seconds (2.04 M allocations: 136.764 MiB, 0.46% gc time, 99.47% compilation time)
This is probably a result of the code emitted by CBinding being rather redundant and relying on the Julia compiler optimizations to remove the redundancies. As the example below illustrates, the first time construction is 99.9% compilation time, but successive calls are much better.
julia> module LargeArray
using CBinding
c``
c"""
typedef char LA[1024];
"""j
end
Main.LargeArray
julia> @time LargeArray.LA("example"...);
3.977991 seconds (2.29 M allocations: 211.621 MiB, 0.65% gc time, 99.92% compilation time)
julia> @time LargeArray.LA("example"...);
0.000050 seconds (109 allocations: 20.781 KiB)
I will see about emitting more to-the-point code which doesn't use the compiler as a crutch. :wink:
Thank you for your quick response! This a workaround a can work with for now! :-)