GithubHelp home page GithubHelp logo

Optimize voice loading about mimic1 HOT 4 OPEN

mycroftai avatar mycroftai commented on June 5, 2024
Optimize voice loading

from mimic1.

Comments (4)

zeehio avatar zeehio commented on June 5, 2024

I will write what I would do, but feel free to take the approach you prefer:

In order to optimize only what needs to be optimized, I would write a simple unittest-like program that loads the Mycroft voice from a file and prints the time it takes to load it. Then I would run it several times to get an estimate of the performance on my computer.
Then I would try those optimizations from easier to harder.

  • inline functions seems easy but if the compiler is smart enough it should do it automatically so I don't expect a huge gain there. I don't know how smart compilers are, so I may be wrong here.
  • I have never used setvbuf but if it is easy to setup it should reduce many internal read calls. It may be good.
  • Reducing the number of cst_fread calls is possible up to a limit due to how the file format is set up. Strings are of variable length so I don't know how much can that be optimized.

I believe the slowness is due to either:

  • too many small reads from file (would be solved by setvbuf)
  • too many small cst_alloc calls when creating the cart trees. The solution for this would be to have a big malloc and put several tree nodes all together in there somehow...
  • too many function calls in general. If that is the case we will need to think of a better format for dumping/loading cart trees...

Hope I can be of help!

from mimic1.

forslund avatar forslund commented on June 5, 2024

Thanks for the suggestions. I am also sceptical to inlining the function calls as you say the compiler should be smart enough. Maybe just make them static so the compiler can optimize correctly even when making shared library. (Maybe it already can without static, I'm not up to date with how compiler works nowadays)

I've tried two things so far:

setting a 64k buffer with cstvbuf() reduced read operations from ~17000 down to ~1500 which may be significant for platforms like the raspberry pi. But I could only see a ~5% improvement in loading times on my computer.

Replace the four initial cst_fread() with a single in cst_read_tree_nodes(). No effect on the number of read operations but according to my time measurements the speed improvement is ~10%

I'll look into some sort of block memory allocation.

from mimic1.

forslund avatar forslund commented on June 5, 2024

Small update, I've tried a bunch of minor changes. On my machine I can see ~25% performance improvement.

What I've done:

  • Some more minor function optimizations except for the ones stated above gave a couple of percent each
  • Replace cst_alloc() (which uses calloc()) with malloc() further improves things.

Next steps will be

  • a simple block allocator
  • try to mmap the file

from mimic1.

nodered avatar nodered commented on June 5, 2024

I have around 300MB of free memory on my pi to play with...would a ramdisk help the loading time of the libraries?

I ran a trace with this
strace -o strace ./mimic test

Then did...
cat strace | grep /home/pi/mycroft-core/mimic/lib
cat strace | grep /home/pi/mycroft-core/mimic/.lib

I don't know much about the program but if some of the libraries can be put onto a ramdisk it might help with the performance.

from mimic1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.