Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How much of Perl can be removed?

by hacker (Priest)
on Aug 13, 2002 at 13:23 UTC ( #189778=perlquestion: print w/ replies, xml ) Need Help??
hacker has asked for the wisdom of the Perl Monks concerning the following question:

Being a purist, minimalist and a pedant, it has come to my attention that bringing a Perl interpretor to a PDA with very constrained memory requirements might prove useful, if the power of that interpretor could be leveraged to handle things outside the "norm" of the tool.

I am/was one of the lead developers of the "Bootable Business Card", a business-card sized Linux distribution on a bootable CD that includes hundreds of tools, utilities, and other things on a compressed ISO image (leveraged with cloop, BusyBox, -Os at build-time, etc). In this space and memory-constrained environment, we had to use a script for init, instead of a binary, stripped the --help strings from many of the common binaries to reduce size, and so on. I'm very familiar with trying to pare down the unnecessary cruft.

So I pose this question.. when dealing with a device that has no built-in filesystem (a PalmOS©-based PDA device), how much of Perl can be removed? PalmOS handheld devices don't have a filesystem or "directory" structure, so the code in the interpretor that deals with those things could be removed (there is "Virtual File System" (VFS), but it's only a "pseudo" filesystem). This may change when OS5.1 and later versions come out with native filesystem support on ARM devices, but current devices and the newest OS5 release will not contain this functionality.

Palm devices likely won't be able to take advantage of most of the external modules (File::Copy or IO::Socket for example), so those hooks in the perl interpretor could be removed, as well as most of the documentation (perldoc, et al). Strings inside the binary itself could be removed as well. Someone who is running Perl on their Palm PDA device is probably familiar enough with perl to be able to use it without onboard documentation (or documentation could be stored in HTML and viewed on the Palm in another app such as Plucker).

Is it feasible to get the binary down to ~200k? 300k? I'm looking for other ways to shave down the size, remove the parts that aren't needed, and still retain the functionality that I require. I'm looking to create a resource library, PerlLib.prc that can be called from other applications directly, similar to the MathLib and SysZLib libraries commonly in use.

Python has already been ported to the Palm in the form of Pippy, but I'd like to solicit ideas for ways to bring Perl to the PalmOS© PDA devices and still keep it as small as possible.

Comment on How much of Perl can be removed?
Re: How much of Perl can be removed?
by KM (Priest) on Aug 13, 2002 at 13:33 UTC
    Why not get involved with Perl 1?

    "This version of perl has many advantages over its far more bloated modern rivals. The source kit is barely 1% the size of the current language distributions, and the resulting executable is also much smaller, making it ideal for embedded use."

    Cheers,
    KM

Re: How much of Perl can be removed?
by Joost (Canon) on Aug 13, 2002 at 13:34 UTC
    You might be interested in Microperl and some other microperl link

    From the readme:

    microperl is supposed to be able a really minimal perl, even more minimal than miniperl. No Configure is needed to build microperl, on the other hand this means that interfaces between Perl and your operating system are left very -- minimal. All this is experimental. If you don't know what to do with microperl you probably shouldn't. Do not report bugs in microperl; fix the bugs +. If you are still reading this and you are itching to try out microperl +: make -f Makefile.micro
    -- Joost downtime n. The period during which a system is error-free and immune from user input.
Re: How much of Perl can be removed?
by Abigail-II (Bishop) on Aug 13, 2002 at 13:43 UTC
    It depends on how you look at it. One could argue "nothing". Remove anything, and it's no longer Perl. On the other hand, one could say "almost everything". Remove everything from Perl till all you have left is C, and you can do anything with it that you can with Perl. And you don't even need to stop there - there are a lot of things that can be removed from C as well. For instance, you can get rid of all the libraries, including 'libc'.

    Of course, what you really want is something only you can answer. After all, you write:

    I'm looking for other ways to shave down the size, remove the parts that aren't needed, and still retain the functionality that I require.
    What the functionality is that you require is only you can answer. And what's needed? OO isn't needed, regexes aren't needed, hashes aren't needed, dynamic loading of libraries aren't needed, XS isn't needed, looping constructs aren't needed, references aren't needed, strings aren't needed, in fact, very little is "needed".

    But would it be Perl?

    Abigail

Re: How much of Perl can be removed?
by Elian (Parson) on Aug 13, 2002 at 15:17 UTC
    Whittling perl down that far is not likely, unfortunately. Even if you tossed everything you're still going to end up with a good-sized executable. (My 5.005_03 perl is about a half-meg)

    The bigger problem you'll run into with perl is the size of individual segments of code. IIRC the palms can't handle segments larger than 64K. Chunks of the tokenizer and parser are, IIRC, larger than that.

    If you do take a shot at this, consider one of the pre-unicode perls--5.004_05 would be a good one. It's got plenty of Pure Perl Power, and since you'll be running without libraries the fact that most things won't build on it any more doesn't really matter.

Re: How much of Perl can be removed?
by Courage (Parson) on Aug 13, 2002 at 20:33 UTC
    Speaking of perl on PocketPC, I participated a bit porting 5.8.0 into WinCE, and can confirm it living there with (almost) full health, with PerlIO layers and most core modules, even most of them passed most tests. (Cassiopeia E125 is my config)

    Speaking of minimal distribution on the other side, I can share another my experience: I succeeded "packing" perl-5.6.1+Tk+Compress::Zlib+(some-other-modules) into some 20 files, most of which are dll-s on my Win32 machine and all text modules being packed into "modules.pm" file (~130Kb in size) which at bootstrap time is unpacked into normal perl modules set.

    Having in total 20 files with total size of ~2Mb I have perl with Tk and those selected modules, which I often use. Very convenient to make independent distributions...

    Courage, the Cowardly Dog
    things, I do for love to perl...

      I'm running PerlCE on my iPaq and it seems to work well. I keep this build on a storage card. IO::Socket, Win32::Serial, Win32::API and Win32::OLE are in there, and some modules can be brought over. I haven't found much doco on the net for api calls on ce, but I haven't looked very hard either.

      I've only really used PerlCE to run a while loop and feed text into the flite program, but I'm planning on using it to read data from my gps, log it, then make announcements based on location. (flite is the festival lite engine ported to ce, you can use it to make your pda talk, available on the same site.)
Re: How much of Perl can be removed?
by John M. Dlugosz (Monsignor) on Aug 13, 2002 at 21:04 UTC
    I use a PocketPC, not a Palm, so I can't really understand how it can work without a file system. The apps have to store the data somewhere, right? And if you eliminate normal files from Perl, (1) how does the perl executable get the specific Perl script to operate on, and (2) how will that program have anything to do? No "files" as we know them, but you still need to replace it with something else to do input and output.
      What hacker is looking to do here is not create a Perl executable for PalmOS, but rather a set of libraries. A programme could call the Perl libraries to run certain functions that might perform better in Perl rather than machine code or C. It's also easier, sometimes, just to use Perl because, heck, it gets the job done.

      If someone had a bit of Perl code they wanted to run that would, say, sort an array, the coder would write the C code for the programme, then write the Perl code for that function, and using the Perl library, he would call the Perl code from within the Palm executable.

      The Palm series of handhelds has no filesystem, but it does have methods of storing data. It stores data into a built-in RAM chip that gets written to ROM on power down. Data is stored in Palm database files (known as .pdb's on a computer file system) that are transferrable to the computer to which the Palm normally HotSyncs.

      Yes, I do own a Palm ;^).

      ~Michael Ryan
      michael (at) lacklustre.net

Re: How much of Perl can be removed?
by dimmesdale (Friar) on Aug 13, 2002 at 22:37 UTC
    Well, how patient are you :)

    I seemed to remember hearing something about this on the Perl6 web site, but couldn't locate it readily.

    After a google search, I found it in PDD1. Maybe this would interest you?

    VARIATIONS ON A THEME

    One of the explicit goals of perl 6 is to generate Java bytecode and .NET code, as well as to run on small devices such as the Palm. The modular nature of perl 6 makes this reasonably straightforward.

    Perl for small platforms

    For small platforms, the parser, compiler, and optimizer modules are replaced with a small bytecode loader module which reads in perl bytecode and passes it to the interpreter for execution. No string eval, do, use, or require is available, though loading of precompiled modules via do, use, or require may be supported.

    ...

Re: How much of Perl can be removed?
by theorbtwo (Prior) on Aug 14, 2002 at 06:17 UTC

    I think, if you're willing to forego string eval (which is more prevailant then you think: file-do is a form of string-eval, require is a form of file-do, and use is a form of require -- and I'm extending it to go as far as compilation of the original input program), you can cut down on the size of the perl interpreter significatly... at the expense of destroying the ablity to develop perl from the PDA, which was probably part of the point of the exercise.

    You'd have to do the ripping-out work, create a perlio OS layer to treat records in the Palm DB as files, and create a perl bytecode loader in XS/C, rather then Perl, and tie it together. It's hardly insignificant, but should be doable.

    My devel box is down, so I can't even give you very loose numbers, unfornatly.


    Confession: It does an Immortal Body good.

Re: How much of Perl can be removed?
by ash (Monk) on Aug 14, 2002 at 09:43 UTC
    You know... Michael Schwern just started maintaing perl 1 :o)

    "Stability. Speed. Simplicity. perl1 is here."
    See: Perl1 News@ perl1/dev

    -- Ash/asksh <ask@unixmonks.net>
Re: How much of Perl can be removed?
by hatter (Pilgrim) on Aug 14, 2002 at 13:10 UTC
    Perl (miniperl, to be precise) is already available on my PDA, and for anyone else with vaguely modern EPOC, more details can be found on http://www.science-computing.de/o.flebbe/perl/ The readme lists what doesn't work, and it's not a very long readme; if I'm not mistaken, you've got more processing power on a palm, too.

    That said, I don't think your question is 'how small could perl be without a file system ?" but "how can I make perl think palmos has a FS ?" because miniperl seems to support a reasonable number of modules, and you're somewhat more limited by perl if you can't use arbitrary modules.

    the hatter

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://189778]
Approved by Hero Zzyzzx
Front-paged by newrisedesigns
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (17)
As of 2014-09-16 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (24 votes), past polls