Skip to content
  • Alexis King's avatar
    linker: Avoid linear search when looking up Haskell symbols via dlsym · e008a19a
    Alexis King authored and Marge Bot's avatar Marge Bot committed
    See the primary Note [Looking up symbols in the relevant objects] for a
    more in-depth explanation.
    
    When dynamically loading a Haskell symbol (typical when running a splice or
    GHCi expression), before this commit we would search for the symbol in
    all dynamic libraries that were loaded. However, this could be very
    inefficient when too many packages are loaded (which can happen if there are
    many package dependencies) because the time to lookup the would be
    linear in the number of packages loaded.
    
    This commit drastically improves symbol loading performance by
    introducing a mapping from units to the handles of corresponding loaded
    dlls. These handles are returned by dlopen when we load a dll, and can
    then be used to look up in a specific dynamic library.
    
    Looking up a given Name is now much more precise because we can get
    lookup its unit in the mapping and lookup the symbol solely in the
    handles of the dynamic libraries loaded for that unit.
    
    In one measurement, the wait time before the expression was executed
    went from +-38 seconds down to +-2s.
    
    This commit also includes Note [Symbols may not be found in pkgs_loaded],
    explaining the fallback to the old behaviour in case no dll can be found
    in the unit mapping for a given Name.
    
    Fixes #23415
    
    Co-authored-by: Rodrigo Mesquita (@alt-romes)
    e008a19a