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

Long compilation time for large Carrays #98

Open
jmark opened this issue May 4, 2022 · 2 comments
Open

Long compilation time for large Carrays #98

jmark opened this issue May 4, 2022 · 2 comments

Comments

@jmark
Copy link

jmark commented May 4, 2022

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)
@krrutkow
Copy link
Member

krrutkow commented May 6, 2022

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. 😉

@krrutkow krrutkow changed the title Very long evaluation time for instantiating structs with large char arrays Long compilation time for large Carrays May 6, 2022
@jmark
Copy link
Author

jmark commented May 9, 2022

Thank you for your quick response! This a workaround a can work with for now! :-)

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

No branches or pull requests

2 participants