A couple of ideas

Raab, Andreas Andreas.Raab at disney.com
Fri Jan 21 00:12:06 UTC 2000


Chris,

I've been thinking about these issues for some time so here are a couple of
comments:

> A Really Cool Thing to do would be to add support for zlib, an
> open-source general-purpose compression library, to the image
> loading/saving code so that Squeak can optionally load and save
> compressed images.  This could save a nice chunk of disk space and
> bandwidth, especially on PDAs, one-disk Squeak systems and the
> Netscape plugin.

This is quite possible though for the time being it would require putting a
lot more stuff on the VM level than we might want to (right now there is
just one little primitive that does the actual work). On the other hand it
would be quite a hack to identify the absolute minimal set of classes that
are required to run this stuff and have the actual image decompressed from
some bootstrap image containing just these few classes (the bootstrap image
could probably be in the 200k range - if not less). This could all be done
inplace, basically replacing the currently running image with the one that
gets decompressed.

> ZLib uses the gzip format so if your system doesn't have it (zlib)
> installed or your VM doesn't support it, you can simply unzip an image
> with gunzip, which is stand-alone (no licensing issues), portable and
> open-source.

Ahem - you are aware that there's GZipReadStream/GZipWriteStream and
ZLibReadStream/ZLibWriteStream in the image, are you?! [see below]

> And on a related note, another Really Cool Thing to do is:
> 
> Replace the current mechanism for storing source code--an index into
> the changes file--with a class (call it MethodSource) that handles
> this.
> 
> Then, add to MethodSource the ability to switch between storing source
> in an external file or in internal Strings.  When switching from
> strings to changes file, all the source code is immediately written
> out to the file.  When switching from changes file to strings, all but
> the current version of each method's source would have to be abandoned
> or the image would get too big.

If you're willing to use decompiled source you can have it right now - Dan
has added a really neat hack that preserves the temps for decompiled methods
and that way all you're really loosing is the comments.

> The typical Squeak newbie simply needs to download the VM for his/her
> platform and a copy of the Uberimage (which, because somebody followed
> my previous suggestion, is compressed), then run the VM on the image.
> The first thing this does (due to a bit of startup code) is write out
> the relevant .sources and .changes file.

Don't forget that you could just include the entire sources/changes in a
Smalltalk literal, so there's no real need for internalizing the method
source. The startup code could just create the changes/sources from the
compressed literal string.

> So, anyone want to implement this?  (I have way more ideas than time,
> so I might get to it but probably not this year.)

It's not so hard as it sounds. Here's a trivial version:

SystemDictionary>>saveWithSources: quitting
	| compressedSource |
	compressedSource := self compressedSourceFiles.
	resuming := self snapshot: true andQuit: quitting.
	self decompressSourceFilesFrom: compressedSource.
	^resuming

compressedSourceFiles
	"Smalltalk compressedSourceFiles"
	| zipped result buffer unzipped |
	result := Dictionary new.
	1 to: 2 do:[:i|
	FileDirectory default deleteFileNamed:'tmp.gz' ifAbsent:[].
	zipped := FileDirectory default newFileNamed:'tmp.gz'.
	zipped binary.
	zipped := GZipWriteStream on: zipped.
	buffer := ByteArray new: 50000.
	unzipped := SourceFiles at: i.
	unzipped binary; reset.
	'Compressing ', unzipped name displayProgressAt: Sensor cursorPoint
		from: 0 to: unzipped size
		during:[:bar|
			[unzipped atEnd] whileFalse:[
				bar value: unzipped position.
				zipped nextPutAll: (unzipped nextInto:
buffer)].
			zipped close.
			unzipped close].
		result at: (SourceFiles at: i) localName 
			put: (zipped encodedStream contentsOfEntireFile).
	].
	self openSourceFiles. "Reopen"
	^result

decompressSourceFilesFrom: aDictionary
	| unzipped buffer zipped |
	Smalltalk closeSourceFiles. "Just in case"
	buffer _ ByteArray new: 50000.
	aDictionary keysAndValuesDo:[:name :compressed|
		FileDirectory default deleteFileNamed: name ifAbsent:[].
		zipped _ GZipReadStream on: compressed.
		unzipped _ FileDirectory default newFileNamed: name.
		unzipped binary.
		'Extracting ', name displayProgressAt: Sensor cursorPoint
			from: 0 to: zipped sourceLimit
			during:[:bar|
				[zipped atEnd] whileFalse:[
					bar value: zipped sourcePosition.
					unzipped nextPutAll: (zipped
nextInto: buffer)].
				zipped close.
				unzipped close].
	].
	Smalltalk openSourceFiles. "Reopen"


  Andreas





More information about the Squeak-dev mailing list