Import pyrevit vs import Autodesk

I’ve noticed that when I import pyrevit as opposed to importing Autodesk directly, I get a performance hit of a few seconds. For example, lets say I have a simple script where I only need Autodesk.Revit.DB imported. If I import as “import Autodesk.Revit.DB as DB”, the script runs very quickly. But if I import as “from pyrevit import DB”, the script takes a few seconds before executing, presumably because of all the stuff it has to load from pyrevit.

Is there a way around the lag? is there a better way to import pyrevit? there are some things importing pyrevit is invaluable for (forms, script), but the slowness is a bummer

Just a little test example:

This code runs in 19.5 seconds:

import time
st = time.time()
from pyrevit import revit, DB
doc = revit.doc

worksets = [
    'ARCH - Core and Shell',
    'ARCH - Interior Buildout',
    'ARCH - RCP',
    'ARCH - Furniture',
    'ARCH - Render',
    'REVIT - MEP',
    'REVIT - Structural',
    'CAD - Survey',
    'CAD - Landscape'
    ]

if not doc.IsWorkshared:
    doc.EnableWorksharing("Shared Levels and Grids", "Workset1")

t = DB.Transaction(doc, 'Create Worksets')
t.Start()
for w in worksets:
    DB.Workset.Create(doc, w)
t.Commit()

print time.time() - st

and this code takes 16.1 seconds:

import time
st = time.time()
import Autodesk.Revit.DB as DB
doc = __revit__.ActiveUIDocument.Document

worksets = [
    'ARCH - Core and Shell',
    'ARCH - Interior Buildout',
    'ARCH - RCP',
    'ARCH - Furniture',
    'ARCH - Render',
    'REVIT - MEP',
    'REVIT - Structural',
    'CAD - Survey',
    'CAD - Landscape'
    ]

if not doc.IsWorkshared:
    doc.EnableWorksharing("Shared Levels and Grids", "Workset1")

t = DB.Transaction(doc, 'Create Worksets')
t.Start()
for w in worksets:
    DB.Workset.Create(doc, w)
t.Commit()

print time.time() - st

A few seconds generally isn’t a big deal and when I don’t need ‘forms’ or ‘script’, I will probably avoid importing pyrevit, but I’m just curious if there is something I could do differently. Thanks!

Hi, I’m experiencing the same performance slowness with “from pyrevit import forms, script”
Sometimes the cursor is spinning for around 10 seconds before running the first line of actual code. Does anyone know what the problem is or experience the same thing?