Script performance problems when running outside MM

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

xnickmx
Posts: 2
Joined: Thu Sep 10, 2009 11:19 am

Script performance problems when running outside MM

Post by xnickmx » Thu Sep 10, 2009 12:16 pm

I would like to export the contents of the MediaMonkey library as an XML file using an external script or application. I have noticed severe performance issues when using an external program compared to running the script inside of MediaMonkey. Does anyone know why that might be?

I have tried to export the ~8600 tracks in my library in three different ways:

1. Script inside of MediaMonkey invoked from the menu (this takes 20 seconds)
2. The same script, invoked from the command line with wscript (this takes 13:06)
3. A C# program that uses the MM COM objects (2:48)

Why would the same script, when invoked from the command line take ~40 times as long when compared to running inside of MM? Why would the C# version take ~8.5 times as long?

I would prefer to run the script externally, so as to avoid having to install the script in MM (edit the ini file, place it in the right folder), but the performance hit is too severe. Does anyone have any tips for me?

Thanks!

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Script performance problems when running outside MM

Post by trixmoto » Fri Sep 11, 2009 3:30 am

It probably works quicker because to connect via COM it needs to run MM silently, whereas if you are running it inside MM then MM is already running. For it to be taking so much extra time I can only imagine that it is connecting to MM several times as well, instead of just once.

Maybe if you want to run the script externally you should try using a COM object to access the database directly instead of connecting to MM and using the API methods. My "BackupPlaylists" script does this, if I remember correctly.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

xnickmx
Posts: 2
Joined: Thu Sep 10, 2009 11:19 am

Re: Script performance problems when running outside MM

Post by xnickmx » Fri Sep 11, 2009 12:16 pm

trixmoto wrote:It probably works quicker because to connect via COM it needs to run MM silently, whereas if you are running it inside MM then MM is already running. For it to be taking so much extra time I can only imagine that it is connecting to MM several times as well, instead of just once.

Maybe if you want to run the script externally you should try using a COM object to access the database directly instead of connecting to MM and using the API methods. My "BackupPlaylists" script does this, if I remember correctly.
I didn't actually know that I could run MM silently. Here is the VBScript code that I am using to get a MM COM object when running externally:

Code: Select all

Set SDB = CreateObject("SongsDB.SDBApplication")
That starts up the MM application. Is there some way to get a MM COM object without showing the application's UI?

I then get the list of songs from the Database object:

Code: Select all

Set list = SDB.Database.QuerySongs("SongLength > 0")
What do you mean by accessing the database directly? Are you connecting directly to the MS Access DB and completely bypassing the MM API?

Once I have my list iterator, I just iterate through the list, one track at a time.

flashk
Posts: 188
Joined: Sun Dec 11, 2005 5:04 pm

Re: Script performance problems when running outside MM

Post by flashk » Fri Sep 11, 2009 12:33 pm

I've developed an external application that accesses MM through the COM interface, and I've also noticed that the performance is drastically slower than an embedded script. I'm not 100% sure why, but I believe it's because COM has to perform extra work when passing data across process boundaries. When the script is embedded it is sharing the same memory space as MM, so it has direct access to the data. I could be wrong though.

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Script performance problems when running outside MM

Post by trixmoto » Sat Sep 12, 2009 7:13 am

Yes, by connecting to the database I do mean bypassing the API, but as it's an SQLite database you cannot use MS Access. In my "BackupPlaylists" script I use the "LiteX.LiteConnection" COM object to do this, take a look at the script code.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Post Reply