There's a bunch of helpful information on the related github issue #38
but I'll try to summarize some of the more important points and answer your questions here.
Labscript (the python package) saves a copy of your labscript (i.e. your python file that describes your sequence), as well as copies of some other modules that it imports, into the shot's hdf5 file in its 'labscriptlib' group. That's great because it gives you a record of the instructions used to compile the shot. In addition to that, by default labscript saves the output of some mercurial functions to the hdf5 file as attributes of the objects in the hdf5 file's 'labscriptlib' group. This is useful because you can see which mercurial commit you were on when you compiled the shot and see if there were any changes in your working version of the code since your last commit. That doesn't really tell you much that the full copies of the files didn't already tell you, but it can still be helpful. Not surprisingly, the code to do this was written back when labscript version control was done with mercurial, which is why mercurial is used there.
Unfortunately, the mercurial commands can take a while to execute and will often be the slowest part of the compilation. If you import more of your modules, the mercurial commands will be run on more files. That's why you see the number of mercurial command executions increase when you use your unit conversion class. Labscript will attempt to run those commands even if you don't use mercurial for version management of your labscriptlib, and it will attempt to run them even if you don't have mercurial installed at all.
There are a few options for speeding this up. The simplest is to set `labscript.compiler.save_hg_info = False` at the top of your labscript. This will prevent the mercurial commands from being run at all, which speeds things up at the cost of not saving the mercurial information. That doesn't cost you anything though if you don't use mercurial for version controlling your labscriptlib.
Alternatively, labscript PR #72
(which is still under review and hasn't been merged into mainline labscript) resolves this issue another way. It caches the output of the mercurial commands and only re-runs the commands when a file changes. So the first shot compilation after starting runmanager may be slow still but the subsequent ones will be much faster because the mercurial commands won't be re-run. The mercurial information will still be saved to the shot files though using the cached results. That PR also adds support for doing this same thing with git instead of mercurial, which is helpful if you use git to manage your labscriptlib. If you have a developer labscript install and want to go this route, checkout the code in the PR, then optionally add the following section to your labconfig, setting the options to True or False as desired:
save_hg_info = False
save_git_info = True
If you need additional compilation speedup, Phil made some further optimizations in labscript PR #73
which you can try out as well.