Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow import #1175

Closed
bjg2 opened this issue Aug 18, 2021 · 5 comments
Closed

Slow import #1175

bjg2 opened this issue Aug 18, 2021 · 5 comments

Comments

@bjg2
Copy link

bjg2 commented Aug 18, 2021

Hi guys. Thanks for this great tool!

I'm running multiple python scripts, even on demand, and there is non-trivial time that goes to importing essentia standard and essentia streaming. These two lines take ~1.75s, which is really lot, more than a third of general processing time in average:

import essentia.standard
import essentia.streaming

Is there any way to speed this up (that is not a keeping running server is communicated with tasks and that executes via multiprocessing, which is also slow)?

Thanks, Aleksandar

@bjg2
Copy link
Author

bjg2 commented Aug 18, 2021

In general, it would be helpful to know if there is a faster way to do this computation? This code is the only thing we need, for audio files up to 2 hours long. Processing takes ~90s for 2h audio, ~2.5s for 3 min audio, but it always has ~1.75s spent in importing essentia standard / streaming (it would be really good if we could somehow remove that lag).

import sys, math, essentia
import essentia.standard
import essentia.streaming

# args
inFile = sys.argv[1]
resultFile = sys.argv[2]

# consts
samplesPerSecond = 24
freqBands = [20, 90, 200, 600, 3000, 8000, 20000]

# number of samples
sampleN = math.floor(2 * 60 * 60 * samplesPerSecond)

# time point for each sample
points = []
for sampleI in range(sampleN):
  points.append(sampleI/24)

# get beat loudness and band ratio

loader = essentia.streaming.MonoLoader(filename=inFile)
beatsLoudness = essentia.streaming.BeatsLoudness(beats=points, frequencyBands=freqBands)

pool = essentia.Pool()

loader.audio >> beatsLoudness.signal
beatsLoudness.loudness >> (pool, 'loudness')
beatsLoudness.loudnessBandRatio >> (pool, 'loudnessBandRatio')

essentia.run(loader)

# output the results as json
essentia.standard.YamlOutput(format = 'json', filename = resultFile)(pool)

@alaasamergit
Copy link

anyone solved the speed issue?

dbogdanov added a commit that referenced this issue Dec 1, 2023
New `ESSENTIA_PYTHON_NODOC` env variable for faster Python package
imports. Skip loading an instance of each algorithm to populate __doc__ and
__struct__ fields in its wrapper class, when this varaible equals to 'True',
'true' or '1'.
@dbogdanov
Copy link
Member

dbogdanov commented Dec 1, 2023

This is solved in #1388 by setting the environment variable ESSENTIA_PYTHON_NODOC=1.

@alaasamergit
Copy link

Could you please explain to us what exactly is solved? and how does it affect the speed?

@dbogdanov
Copy link
Member

dbogdanov commented Dec 2, 2023

On the import, all algorithms are instantiated once to populate the __doc__ and __struct__ fields in the Python algorithm wrapper classes (e.g., see import essentia.standard as es; es.MonoLoader.__doc__). These fields aren't necessary except for interactive help in IPython, so the entire process can be skipped. New environmental variable ESSENTIA_PYTHON_NODOC=1 bypasses it, speeding up the import from ~3.5 s to ~0.3 s on my (slow) testing machine.

Follow #1388 for future updates for when the new Python wheels are available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants