[vtk-developers] Speeding up `import vtk`

David Gobbi david.gobbi at gmail.com
Thu Sep 8 13:39:07 EDT 2016


There could be a way to change the behavior of "import vtk", e.g.

import vtk_settings
vtk_settings.modules = [ ... ] # whitelist of desired modules?
import vtk

The .py files for the VTK modules are actually a bit silly, since they just
waste time moving classes from the .pyd module to the .py module.  We
should build vtkCommonCore.pyd directly (instead of building
vtkCommonCorePython.pyd).

 - David


On Thu, Sep 8, 2016 at 11:24 AM, Utkarsh Ayachit <
utkarsh.ayachit at kitware.com> wrote:

> The problem with that is it will have to be an entirely new package.
> Further complication, this package cannot use any of *.py files for
> VTK modules or others from the vtk package since as soon as it does
> that vtk/__init__.py will import everything. So we'll need to
> duplicate all the *.py files too.
>
> On Thu, Sep 8, 2016 at 1:14 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> > Hi Utkarsh,
> >
> > As usual, I'm a stickler for backwards compatibility and would rather go
> in
> > the other direction,
> >
> >   import vtkminimal as vtk
> >
> >  - David
> >
> >
> > On Thu, Sep 8, 2016 at 10:55 AM, Utkarsh Ayachit
> > <utkarsh.ayachit at kitware.com> wrote:
> >>
> >> Folks,
> >>
> >> This is in reference to this:
> >> https://gitlab.kitware.com/vtk/vtk/issues/16780
> >>
> >> `import vtk` is slow because it imports all of VTK. It isn't the best
> >> practice, and has no workaround -- given the current implementation
> >> where all the modules are imported in vtk/__init__.py itself.
> >>
> >> I have an MR in progress that addresses this issue:
> >> https://gitlab.kitware.com/vtk/vtk/merge_requests/1921
> >>
> >> This MR does the following:
> >> * vtk/__init__.py no longer imports all of VTK.
> >> * vtk/all.py is a new module that imports all of VTK.
> >>
> >> This does break old scripts, but provides an easy workaround. For
> >> users who want to keep previous behavior, they can simply do the
> >> following:
> >>
> >>    from vtk import all as vtk
> >>
> >> Thoughts? If this looks reasonable to everyone, I'll update the MR to
> >> fix all tests accordingly.
> >>
> >> Thanks
> >> Utkarsh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20160908/7ede5023/attachment-0001.html>


More information about the vtk-developers mailing list