exporting imports to reduce exe size?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron_Adam

    #1

    exporting imports to reduce exe size?


    In looking at ways to reduce the size of exe's created with py2exe,
    I've noticed that it will include a whole library or module even if I
    only need one function or value from it.

    What I would like to do is to import individual functions and then
    export 'write' them to a common resource file and import that with
    just the resources I need in them.

    Has anyone tried this?

    I'm considering using pickle to do it, but was wondering if this is
    even a viable idea?

    Is it possible to pickle the name space after the imports and then
    reload the name space in place of the imports later?

    Cheers,
    Ron

  • Chris Cioffi

    #2
    Re: exporting imports to reduce exe size?

    My first thought is what if the function you are using uses other
    functions(maybe not exported by the module/package)? For example: if
    some_func() makes a call to _some_weird_mod ule_specific_fu nc(), how
    are you going to make sure you get the
    _some_weird_mod ule_specific_fu nc function? This doesn't even start to
    work when the function you are interested in is also using functions
    from other modules/packages.

    Besides, what py2exe is really doing is grabbing the .pyo or .pyc
    files and throwing them in a zip file. Is it really worth the effort
    to save a 100K or so, at most?

    Chris

    On Apr 12, 2005 10:54 AM, Ron_Adam <radam2_@_tampa bay.rr.com> wrote:[color=blue]
    >
    > In looking at ways to reduce the size of exe's created with py2exe,
    > I've noticed that it will include a whole library or module even if I
    > only need one function or value from it.
    >
    > What I would like to do is to import individual functions and then
    > export 'write' them to a common resource file and import that with
    > just the resources I need in them.
    >
    > Has anyone tried this?
    >
    > I'm considering using pickle to do it, but was wondering if this is
    > even a viable idea?
    >
    > Is it possible to pickle the name space after the imports and then
    > reload the name space in place of the imports later?
    >
    > Cheers,
    > Ron
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >[/color]


    --
    "I was born not knowing and have had only a little time to change that
    here and there." -- Richard Feynman

    Comment

    • Ron_Adam

      #3
      Re: exporting imports to reduce exe size?

      On Tue, 12 Apr 2005 12:14:38 -0400, Chris Cioffi
      <evenprimes@gma il.com> wrote:
      [color=blue]
      >My first thought is what if the function you are using uses other
      >functions(mayb e not exported by the module/package)? For example: if
      >some_func() makes a call to _some_weird_mod ule_specific_fu nc(), how
      >are you going to make sure you get the
      >_some_weird_mo dule_specific_f unc function? This doesn't even start to
      >work when the function you are interested in is also using functions
      >from other modules/packages.
      >
      >Besides, what py2exe is really doing is grabbing the .pyo or .pyc
      >files and throwing them in a zip file. Is it really worth the effort
      >to save a 100K or so, at most?
      >
      >Chris
      >[/color]

      I think in some cases it could save quite a lot more than 100k when
      you consider that the module you include to get a single function,
      then may include 3 modules for other functions you don't need, and
      they in turn do the same.

      After looking into it some, I agree it's probably not worth the
      effort. Pythons pickle, shelve, and marshal functions don't work on
      most module objects, so it's pretty much a dead end.

      It would need be doable in a simple and general way to be worth while.

      Thanks anyways,

      Ron

      Comment

      • Mike Meyer

        #4
        Re: exporting imports to reduce exe size?

        Ron_Adam <radam2_@_tampa bay.rr.com> writes:
        [color=blue]
        > In looking at ways to reduce the size of exe's created with py2exe,
        > I've noticed that it will include a whole library or module even if I
        > only need one function or value from it.
        >
        > What I would like to do is to import individual functions and then
        > export 'write' them to a common resource file and import that with
        > just the resources I need in them.[/color]

        It's not clear you can use a common "resources" file. You need to copy
        the namespaces represented by each module into separate namespaces in
        the file you're going to import. Multiple files can do this, but there
        may be another approach.
        [color=blue]
        > Has anyone tried this?
        >
        > I'm considering using pickle to do it, but was wondering if this is
        > even a viable idea?[/color]

        Yeah, it's viable. LISP has been doing it for quite a while.

        However, note that you have to figure out what objects in each module
        are needed in each function you call from that module, and recursively
        examine each of those objects. It's a non-trivial thing to do, and
        will rely heavily on introspection of the objects in question.

        <mike
        --
        Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
        Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

        Comment

        Working...