[vtk-developers] Speeding up `import vtk`

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Thu Sep 8 13:24:08 EDT 2016


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


More information about the vtk-developers mailing list