Pymel.core import in Maya 2018 super slow

I’ve been using Pymel in several Maya versions and it’s always been fast to start up. But now in Maya 2018, it’s very slow (20 - 30 seconds)to import it the first time I use it during the session.

The script editor gives this readout when I import it the first time:
// pymel.core : Updating pymel with pre-loaded plugins: svgFileTranslator, invertShape, mayaHIK, GamePipeline, CloudImportExport, curveWarp, tiffFloatReader, MASH, poseInterpolator, ATFPlugin, hairPhysicalShader, CharcoalEditor, ikSpringSolver, ik2Bsolver, AbcExport, retargeterNodes, VectorRender, gameFbxExporter, OpenEXRLoader, lookdevKit, Unfold3D, mayaCharacterization, Type, mtoa, meshReorder, modelingToolkit, rotateHelper, matrixNodes, AbcImport, autoLoader, deformerEvaluator, sceneAssembly, gpuCache, Substance, OneClick, shaderFXPlugin, objExport, renderSetup, GPUBuiltInDeformer, ArubaTessellator, quatNodes, fbxmaya //

Seems like this “updading” procedure is what makes it slow now. Anyone know why this has been changed, or how I can change it back?

Other people are complaining about this same issue in this thread:

What its doing there is scanning all the loaded plugins, and then wrapping any provided commands with a PyMel version.

This is something PyMel has done since at least Maya2010. The best way to speed that process up would be to unload any plugins you’re not actually making use of.

That makes sense, thanks. However in Maya 2017 I have the same plugins loaded, yet pymel.core imports virtually instantly. So apparently there is some other issue causing pymel import in Maya 2018 to take almost 30 seconds.

Its possible that some other element during startup is doing an import pymel.all operation instead of just an import pymel.core which can be substantially longer. As it is generating all of the various Node classes upfront.

Might be worth doing a quick find in files against your various scripts, and probably against the maya directory itself. Could be that one of the new tools that 2018 added is doing this.

1 Like

Also, could be worth opening an issue on their github.
I personally haven’t run into it appearing any slower than usual during startup. But that doesn’t mean much overall.

** EDIT **

So I did some quick profiling.
The bulk of the work is happening when PyMel is initializing a bunch of mel scripts.
This can be skipped by setting the PYMEL_SKIP_MEL_INIT environment variable.
No clue what that does to overall functionality.
If you just want to skip initializing plugins, you can set skip_initial_plugins=true in the pymel.conf file. (Honestly can’t remember where to place that file for pymel to find it though)

But disabling the mel init shaved about 8 seconds off my import time when run from mayapy.
Which was about 55% of the overall time.

2 Likes

The addition of several very slow-to-initialize plugins in the last couple of years has rendered this even worse than it used to be :frowning:

Yeah, I’m kind of curious if the plugin loading / wrapping could be turned into a lazy operation.
Or maybe at least some mechanism for caching the data so it doesn’t have to rebuild it on the fly every damn time.

I think they have to do it because they do type conversions on their own types. cmds does the same thing but it’s basically free because you only have primitive types.

Yeah, the normal basic PyNodes are built lazily, and it looks like the custom nodes from a plugin are created the same way. They only get created non-lazy if pymel.all is already imported.
The big difference is that the non-plugin nodes are built from a cache, vs being scraped from a plugin.

I’m kind of curious if its actually the wrapping code, or just running the mel initialization code that pymel does, because maya.standalone.initialize is a hell of a lot faster, but it doesn’t run a bunch of mel code that pymel does.

Greetings, was there ever a consensus on the root issue? I’m sure like many of you, I use PyMel on the regular. Does anyone have a good workaround to the recent changes in Maya causing PyMel to exhibit “slower” import performance? Would an executeDefferred call to import pymel.core suffice, after the plugins are initialized and registered? I’m assuming userSetup.py wont be a good place for this as the UI and plugins have not been fully registered yet.