Arc Forumnew | comments | leaders | submitlogin
Eliminating the runtime check on set-c[ad]r in ac.scm
6 points by waterhouse 5235 days ago | 2 comments
The solution is quite simple. I can't believe PG didn't think of this, unless I've made a mistake and this doesn't work, but I've tested it on both mzscheme v372 and racket v5.0 and it seems to work fine. (And it also runs faster; sorting a million-element list takes a bit more than half as long as it did before, running Arc in racket.)

Solution: Find the definitions of x-set-car! and x-set-cdr! in ac.scm. Replace them with the following definitions, and then move them so they come after the definitions of n-set-car! and n-set-cdr!.

  (define x-set-car!
    (let ((fn (namespace-variable-value 'set-car! #t (lambda () #f))))
      (if (procedure? fn)
          fn
          n-set-car!)))
  (define x-set-cdr!
    (let ((fn (namespace-variable-value 'set-cdr! #t (lambda () #f))))
      (if (procedure? fn)
          fn
          n-set-cdr!)))


3 points by waterhouse 5231 days ago | link

For context, by the way, the above is a direct reply to this comment from ac.scm, right before the old definitions of x-set-car! and x-set-cdr!:

  ; decide at run-time whether the underlying mzscheme supports
  ; set-car! and set-cdr!, since I can't figure out how to do it
  ; at compile time.

-----

2 points by aw 5230 days ago | link

Predicting the performance of an optimization is actually quite difficult. I myself had noticed in passing the namespace test being done at runtime, but it had never occurred to me that it would make such a dramatic difference.

You've made quite a valuable contribution by measuring the performance improvement.

-----