aksharamukha-python icon indicating copy to clipboard operation
aksharamukha-python copied to clipboard

Use LRU cache and speed up.

Open vvasuki opened this issue 3 years ago • 2 comments

In case of multiple calls, aksharamukha is too slow.

Example:

Lines: 3%|▎ | 11175/353348 [13:32<7:01:17, 13.54it/s]

I believe this can be resolved by using an LRU cache in case of costly operations like:

    with open(dir_path + "/yaml/aksharamukha-scripts.yaml", 'r') as stream:
        data_loaded = yaml.safe_load(stream)

Tip: if this were a function, you could have used a decorator like https://docs.python.org/3/library/functools.html

vvasuki avatar Jul 19 '22 06:07 vvasuki

A confirmed fix you can copy paste:

@functools.cache
def _load_data():
    import os
    dir_path = os.path.dirname(os.path.realpath(__file__))
    with open(dir_path + "/yaml/aksharamukha-scripts.yaml", 'r') as stream:
        data_loaded = yaml.safe_load(stream)
    return data_loaded


def convert_default(src, tgt, txt, nativize = True, post_options = [], pre_options = []):
    data_loaded = _load_data()

So much better:

Lines: 7%|▋ | 26193/353348 [00:48<08:22, 650.91it/s]

vvasuki avatar Jul 19 '22 06:07 vvasuki

Sweet. Thanks for this. I'll implement and push the changes.

V

virtualvinodh avatar Jul 23 '22 18:07 virtualvinodh

This will be pushed in the next update.

virtualvinodh avatar Jan 03 '23 15:01 virtualvinodh