Hi Guys,
I've attempted to port a few languages onto J2me, then I found Peter
Norvig's Jscheme for Java...
It's compiled size fit our budget and it offered basic Continuations,
and not so basic lambda's, recursive functions, vectors, etc and most
of R4RS. It's kinda stunning how much he fit into so little code.
Well, I haven't hit any big stumbling blocks with the port; of course,
I've had to slash out JavaMethod and any java.lang.reflect calls.
For those who don't know, MIDP 2.0 and CLDC 1.1 is pretty limited
compared to SE. It's missing almost everything in the reflection
department and there's no class loader.
An interpreter like this was very attractive because we can save so
much "building stuff" byte code using downloadable scripts and
documents (sound familar?).
Performance left alot to be desired though, but Peter offers some
helpful hints here, http://www.norvig.com/jscheme-design.html
Peter conjectures that most of the time is spent in linear lookups in
the global environment.
I switched subclasses GlobalEnvironment from Environment and use a
hashtable for setting primitives, defining them and looking them up.
It was a pleasant surprise to see a 100% increase in speed. That is,
it took half the time to do almost everything - from intensive
quicksort tests to simple random vector generation. Sweet!
I'd love to find more simple things that'll improve performance like
that because it's always great to have that things faster. The quicker
I can interpret, the more opportunity there is to include scripts in
tight render loops for controlling positions of sprites/characters on
screen, etc.
Does anyone have any other ideas for performance boosting tweaks?
I suppose anything involving lexicon lookup would help greatly, but I
was thinking more abstract tactics like lambda-pre-analysis or
intermediate interpretation or something fancy.
Anything at the end of the day that'll save cycles will be greatly appreciated.
In regards to the other environment lookups, there is more thinking I
need to do about why Scheme rampantly uses nested Pair's for lists of
things. As elegant as cons'ing things together is, it doesn't perform
terribly well on a mobile virtual machine. It'd be nice if there were
a native Hashtable type in scheme that I could map over to the Java
hashtable. I can further jack performance by using Hashtable's for all
environments, but I'm not particularly sure how to do that for all
Procedure derived types.
Does anyone know of a Hashtable implementation exists in a common
Scheme Library of sorts?
More importantly, I'd like to give what-ever I've written back to the
community. Since I'm working on such an old source tree, adding
patches into the sourceforce truck is probably a bad idea.
Do you think I should start my own project, and just publish the
source in my blog?
Or, should I start commiting to JScheme on sourceforge?
I'm taking a different route for this R4RS implementation. My goals
are to focus on speed and to sacrifice language features/compliance
for runtime speed and platform (j2me +ext_packages) wrapping.
It seems this flavour of Scheme I'm roasting differs quite a bit from
R4RS or R5RS; maybe it's not Scheme at all, and just an incomplete
subset - J2ScheME? J2MEScheme?
Thanks to everyone for a great Scheme port that's small, powerful and nifty.
Hope to hear back,
Vijay Santhanam
|