Skip to content

lookup_linke_turbidity is (still) slow #437

Closed
@cedricleroy

Description

@cedricleroy

Related to #368

From line_profiler @wholmgren, you stated that loading the matlab file was one of the two bottlenecks.

Loading the file is pretty slow, and we are doing it each time we run the function. Could we cache the file in the module to avoid reloading it?

There are actually two ways to see that:

  1. Loading the file when we first call lookup_linke_turbidity
CACHE = {}

[...]

def lookup_linke_turbidity(...):
    [...]
    # try to get `LinkeTurbidity` data from the `CACHE`
    mat = CACHE.get('LinkeTurbidity')
    if not mat:
        # load `LinkeTurbidity` data and save then to the `CACHE`
        mat = scipy.io.loadmat(filepath)
        CACHE['LinkeTurbidity'] = mat
    [...]
  1. Loading the file at import time, and cache it
CACHE = {}

def load_linke_turbidity():
    # scipy import try except + filepath
    CACHE['LinkeTurbidity'] = scipy.io.loadmat(filepath)

load_linke_turbidity()

[...]

def lookup_linke_turbidity(...):
    [...]
    # try to get `LinkeTurbidity` data from the `CACHE`
    mat = CACHE.get('LinkeTurbidity')
    [...]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions