We have a simulator in our company that’s fully written in Julia. The codebase is quite large. We have been suffering from very high latency for some time now. I took the initiative of trying to solve the latency issue but after working on it for a few months now, I have hit a roadblock a need some help because the results I am seeing do not make sense to me. The TTFX for our code is 4 to 6 minutes. After that, depending on the simulation parameters, the simulation can take less than a second to run.
I will explain our code using pseudo-julia-code since this is proprietary code. Here it goes!
function main(input_param_file)
params = read_params(input_param_file)
result_a, result_b, result_c = run_sim(params)
print_res_summary_a(result_a)
print_res_summary_b(result_b)
print_res_summary_c(result_b)
end
function run_sim(params)
# Extract params
param_a = get_param_a(params)
param_b = get_param_b(params)
param_c = get_param_c(params)
# Generate data based on params
data = gen_data(param_a, param_b, param_c)
# Loop
while some_condition
# main processing functions
res_a = process_a(param_a, data)
res_b = process_b(param_b, data)
res_c = process_c(param_c, data)
# Write results to files
dump_results(res_a, res_b, res_c)
end
return res_a, res_b, res_c
end
I made sure that main
, run_sim
and the functions it calls are type-stable. I timed the first call of almost all of the functions above. This is using a reference param file. Here are the results:
function | time (seconds) |
---|---|
main | 229.8 |
run_sim | 8.5 |
process_a | 0.58 |
process_b | 9E-06 |
process_c | 5E-06 |
dump_results | 0.0029 |
As you can see, all of the functions have decent compilation/inference times with the exception of main
and I don’t know why.
Precompiling is an option but it does not solve the fundamental issue we are having. Also, this will be our last resort.
I used SnoopCompile
to get a sense of the amount and impact of runtime inferences. While there are runtime inferences (~150), as far as I can tell, they don’t seem to be affecting the latency that much.
Any help will be deeply appreciated. I will try to provide more information if needed given the proprietary nature of our code.