I am reading through Dybvig's thesis and it's very clearly written and helpful. (I only hope my own thesis is as useful to someone in the future). <div><br></div><div>Jens's tip will help a lot. I have a very stupid representation for all my values right now. Perhaps making it slightly more clever will give me the enough speed up to not worry about performance anymore.</div>
<div><br></div><div>And, now that I check, yes I am in fact type-checking the list structure during variable lookup, which is completely unnecessary. That might be why the profiler is telling me that all the overhead is coming from typechecking. Thank you!</div>
<div><br></div><div> -Patrick<br><br><div class="gmail_quote">On Mon, Mar 21, 2011 at 2:43 PM, Jens Axel Søgaard <span dir="ltr"><<a href="mailto:jensaxel@soegaard.net">jensaxel@soegaard.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
2011/3/21 Patrick Li <<a href="mailto:patrickli.2001@gmail.com">patrickli.2001@gmail.com</a>>:<br>
<div class="im">> Thanks for all the suggestions! I'll look over those and see what's<br>
> happening.<br>
> I have profiled my code, and noticed that it spends most of the time in<br>
> typechecking the arguments to the cons, car, and cdr primitives. I currently<br>
> know of no simple way to eliminate those checks while still giving me<br>
> relatively sane error messages for when things go wrong.<br>
<br>
</div>Which representation do you use? Maybe you can speed up the type checks,<br>
by choosing a clever representation.<br>
<br>
A common trick is to embed type information into the pointers.<br>
In the representation used in the 1996 Scheme Workshop pointers to cons<br>
cells contains 010 in their lower 3 bits. A type check is thus compiled<br>
to a very fast and instruction.<br>
<br>
<a href="http://www.cs.indiana.edu/eip/compile/back.html" target="_blank">http://www.cs.indiana.edu/eip/compile/back.html</a><br>
<br>
--<br>
Jens Axel Søgaard<br>
<div><div></div><div class="h5"><br>
<br>
> -Patrick<br>
><br>
> On Mon, Mar 21, 2011 at 1:39 PM, Vincent St-Amour <<a href="mailto:stamourv@ccs.neu.edu">stamourv@ccs.neu.edu</a>><br>
> wrote:<br>
>><br>
>> David Kranz's dissertation has a lot of interesting material about<br>
>> implementing closures efficiently.<br>
>> <a href="http://repository.readscheme.org/ftp/papers/orbit-thesis.pdf" target="_blank">http://repository.readscheme.org/ftp/papers/orbit-thesis.pdf</a><br>
>><br>
>> Andrew Appel's book Compiling with Continuations also covers similar<br>
>> material.<br>
>><br>
>> Vincent<br>
>><br>
>> At Mon, 21 Mar 2011 12:42:07 -0400,<br>
>> Patrick Li wrote:<br>
>> ><br>
>> > [1 <multipart/alternative (7bit)>]<br>
>> > [1.1 <text/plain; ISO-8859-1 (7bit)>]<br>
>> > Hello everyone,<br>
>> ><br>
>> > For educational purposes, I've implemented a simple Scheme interpreter<br>
>> > in C,<br>
>> > but it's way too slow at the moment. (eg. just macroexpanding and<br>
>> > evaluating<br>
>> > a function definition takes a few seconds.) I would like some advice on<br>
>> > how<br>
>> > to proceed next to get a adequately performing Scheme system.<br>
>> ><br>
>> > My goal is simply to get out of C as quickly as possible. ie. Get the<br>
>> > basic<br>
>> > forms and a macro system working which will allow me to write the rest<br>
>> > of it<br>
>> > in Scheme.<br>
>> ><br>
>> > So far this is what I have done:<br>
>> ><br>
>> > I wrote a simple Scheme interpreter in Scheme in continuation-passing<br>
>> > style,<br>
>> > so that I can get call/cc working.<br>
>> ><br>
>> > Then I basically just manually translated that code into C. So all<br>
>> > continuations are heap allocated.<br>
>> ><br>
>> > How should I proceed from here? These are the options that I've come up<br>
>> > with:<br>
>> ><br>
>> > (1) Optimize variable lookup. Currently the environment is represented<br>
>> > as a<br>
>> > list of key-value pairs. Variable lookup is done by searching through<br>
>> > the<br>
>> > list.<br>
>> ><br>
>> > (2) "Analyze" the code before evaluating it (ie. as in SICP). Ie. for an<br>
>> > (if) form, it will determine that it is an if form during the analysis<br>
>> > phase, so that at execution stage it won't have to repeatedly figure out<br>
>> > what sort of form it is.<br>
>> ><br>
>> > (3) Write a very simple VM, and develop a simple byte-code compiler.<br>
>> > The<br>
>> > problem here is that I don't really know how to deal with first-class<br>
>> > continuations.<br>
>> ><br>
>> > Thanks for your help<br>
>> > -Patrick<br>
>> > [1.2 <text/html; ISO-8859-1 (quoted-printable)>]<br>
>> ><br>
>> > [2 <text/plain; us-ascii (7bit)>]<br>
>> > _________________________________________________<br>
>> > For list-related administrative tasks:<br>
>> > <a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
><br>
><br>
> _________________________________________________<br>
> For list-related administrative tasks:<br>
> <a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
><br>
<br>
<br>
<br>
</div></div>--<br>
--<br>
<font color="#888888">Jens Axel Søgaard<br>
</font></blockquote></div><br></div>