You probably need to rehash! the dictionary after precompilation since the serialized hashes are not valid anymore.
So you can add
function __init__()
Base.rehash!(data)
end
to your module. Also, don’t use the .keys field for dictionaries, it’s an internal field.
Specifically, see this part in the manual Modules · The Julia Language
Dictionary and set types, or in general anything that depends on the output of a
hash(key)method, are a trickier case. In the common case where the keys are numbers, strings, symbols, ranges,Expr, or compositions of these types (via arrays, tuples, sets, pairs, etc.) they are safe to precompile. However, for a few other key types, such asFunctionorDataTypeand generic user-defined types where you haven’t defined ahashmethod, the fallbackhashmethod depends on the memory address of the object (via itsobjectid) and hence may change from run to run. If you have one of these key types, or if you aren’t sure, to be safe you can initialize this dictionary from within your__init__function. Alternatively, you can use theIdDictdictionary type, which is specially handled by precompilation so that it is safe to initialize at compile-time.
So a better solution than I wrote above is likely to use an IdDict