Skip to content

redundant unnecessary repetitive calling of _validate_source_file() in nested loops #139

@Moadab-AI

Description

@Moadab-AI

I am using the latest version of the repository (1.6.4) and when generating soundscapes I noticed a prohibitive slow generation of soundscapes in a loop. here's what I found out:

So following the example in the documentation : https://scaper.readthedocs.io/en/latest/examples.html
in the add_event() method when I specify a list of source files for event (instead of []), every time it wasnt to add an event it will go through validating the entire list of source files because of calling "_validate_source_file()" in "validate_event()" ! this is extremely redundant and unnecessary because Instead of doing so only "one" necessary time it will do it : {number of soundscapes times number of_added_event_per_soundscape} times. particularly if the list of event source files is long (as in my case).

The same argument of course applies when _validate event is called in add_background.
So I believe the _validate_source_file must be moved out of all loops and be just called once for the list of background files and source files through a separate method outside of all the loops.
I am just commenting them out in my case.

Also similary if you dont specify the list of source files in the add_event or add_background and go with [] instead, this redundant file checking happens through another function in utils.py called : "_get_sorted_files()" where in the last line of the method is written:
files = [f for f in files if os.path.isfile(f)]

this line is again is a huge unnecessary overhead and should be performed outside all the loops and only once for all background and source files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions