# Too low cpu usage of Sublime



## McSound (Oct 28, 2019)

Hi to all!
I've noticed that Sublime uses too low cpu, just 2 cores of 16 and about 11% overall cpu usage when compiling. I've just upgraded to i9900 from my old i7 and almost see no difference. How can I make it use more cpu power? My script is quite big and it takes some time to compile.
Thanks.


----------



## EvilDragon (Oct 29, 2019)

You can't. Compiler would need a complete overhaul for more efficiency (also it's Python-based, and Python is not known for its speed). Also note that compiling is mostly a serial process (since various actions are executed one after another because they depend on the result of the previous process), so it cannot be parallelized much. This is why you see just 2 cores active - but in reality that's just one core doing the work (proper core + hyperthreaded one, but in this case they likely behave as a single core).

Big scripts will take time to compile. That's just the way it is with sKSP, so gotta live with it  Unless somebody optimizes it, but that seems a long shot.


----------



## McSound (Oct 29, 2019)

Thanks EvilDragon, at least I know it now) So I'll try to divide my script into parts and compile the piece I need only.


----------



## EvilDragon (Oct 29, 2019)

That's probably gonna slow you down more than it helps, I'd advise against working like that.


----------



## McSound (Oct 29, 2019)

And thank you again, ED! I think I'll follow your advice)


----------



## azrulsaleh (Oct 29, 2019)

McSound said:


> Thanks EvilDragon, at least I know it now) So I'll try to divide my script into parts and compile the piece I need only.



I'm curious. What do you mean by dividing the script into parts and compiling the pieces needed?

Do you mean using import? Multiple scripts with pgs? Or something else?


----------



## McSound (Oct 30, 2019)

No, by "dividing" I mean just leaving only part of code I'm working on and throwing away the rest code for a while. And after successful coding this part I could pile back all together. But ED told that it could only be longer, and I think he's right)


----------



## d.healey (Oct 30, 2019)

How big is your script?


----------



## McSound (Oct 30, 2019)

About 7000 lines of sublime ksp code, when compiled it goes to about 80000. It takes about 1 minute to compile.


----------



## d.healey (Oct 30, 2019)

Big script, what does it do?


----------



## McSound (Oct 30, 2019)

Curious?) It's not for musical purposes It's for post production, you know, foley steps, cloth and other stuff like doors, kitchen appliances and so on. Making for myself to ease my workflow and to avoid wasting money for foley studio on simple budget projects. It's multichannel, has 7 octaves(each channel per octave), each of them is for particular set of items, with its own setting of EQ, Limiter, Reverb and some other things. I think it's hard to explain clearly all this junk, but I hope it would help me a lot.


----------



## azrulsaleh (Oct 30, 2019)

McSound said:


> No, by "dividing" I mean just leaving only part of code I'm working on and throwing away the rest code for a while. And after successful coding this part I could pile back all together. But ED told that it could only be longer, and I think he's right)



Fair enough. I personally find myself creating a new instrument and scripting only the needed functionality in isolation. Takes a split second to compile. Once it works, its a matter of copying and pasting the relevant lines.


----------



## McSound (Oct 30, 2019)

Yeah, in that case compiling takes just a few moments, but when inserting back to main script something's still needed to be fixed and it takes time again. Hoping to find a compromise way.


----------



## EvilDragon (Oct 30, 2019)

That sounds quite inefficient. Obviously a lot of macros are being used.

Maybe you should think about putting some things in functions. I assume a lot of your UI callbacks are also macros that get expanded for each of the channels there, so you get a lot of repetition happening. If you had a function that takes the number of channel as an argument (you could do this with taskfuncs), then executes the necessary UICB stuff, you could greatly reduce your compiled code size.


----------



## McSound (Oct 31, 2019)

Yes, you're right, there's a lot of macros. Ok, I'll try to use functions instead of macros, I've got functions as well though, but now I think not enough. I have to dive back to manuals) Thanks to all of you guys! EvilDragon, very appreciated for your help!


----------



## McSound (Dec 5, 2019)

EvilDragon said:


> If you had a function that takes the number of channel as an argument


I read TCM user guide and must admit that I can't figure out how to use a part of UI variable's name (number of channel in my case) in taskfunc and not using macros at all. Would you be so kind to give me a simple example of using taskfunc this way, please?


----------



## EvilDragon (Dec 5, 2019)

You cannot use a part of variable name without using macros, obviously.

What you need to do is access your UI variables through UI ID which is stored in an array. Then you can easily traverse that array depending on the channel. If you use SublimeKSP it actually just makes that array for you so it's really easy. Very quick example:


```
on init
    define NUM_CHANNELS := 8

    declare i
    declare pers ui_knob Volume[NUM_CHANNELS] (0, 1000000, 1)

    for i := 0 to NUM_CHANNELS - 1
        Volume[i] -> unit := KNOB_UNIT_DB
        Volume[i] -> default := 630000
        Volume[i] -> value := get_engine_par(ENGINE_PAR_VOLUME, -1, -1, $NI_BUS_OFFSET + i)
        Volume[i] -> label := get_engine_par_disp(ENGINE_PAR_VOLUME, -1, -1, $NI_BUS_OFFSET + i)
    end for

    tcm.init(1000)
end on

taskfunc AdjustVol(channel)
    set_engine_par(ENGINE_PAR_VOLUME, Volume[channel] -> value, -1, -1, $NI_BUS_OFFSET + channel)
    Volume[channel] -> label := get_engine_par_disp(ENGINE_PAR_VOLUME, -1, -1, $NI_BUS_OFFSET + channel)
end taskfunc

macro VolKnob(#id#)
on ui_control (Volume#id#)
    AdjustVol(#id#)
end on
end macro

iterate_macro(VolKnob) := 0 to NUM_CHANNELS - 1
```

This adjusts volumes of first 8 instrument busses.


----------



## McSound (Dec 5, 2019)

Ok, I see, macro is still used but the compiled code is much reduced now. Got it! Thanks a lot a lot a lot! And where can I read more about "-> unit" "-> default" and so on syntax? It turns out I don't know much about it , except "-> result" usage in functions. Sorry for newbie's bothering)


----------



## d.healey (Dec 5, 2019)

McSound said:


> Ok, I see, macro is still used but the compiled code is much reduced now. Got it! Thanks a lot a lot a lot! And where can I read more about "-> unit" "-> default" and so on syntax? It turns out I don't know much about it , except "-> result" usage in functions. Sorry for newbie's bothering)











Advanced Usage · nojanath/SublimeKSP Wiki


Fork of Nils Liberg's SublimeKSP plugin. See README for details. - Advanced Usage · nojanath/SublimeKSP Wiki




github.com


----------



## McSound (Dec 5, 2019)

Nice! It seems time to improve my script) Thanks guys!


----------



## McSound (Dec 9, 2019)

Just to report: I succeeded to reduce compiled code from 112000 lines to 11000. Now compiling takes about 4 seconds in Sublime. taskfunc is my best friend now) Thanks again EvilDragon and d.healey for your great patience!


----------

