どの append2 が遅いか?を原始的な方法で特定した

コンパイラ中の append2 呼び出しを append2a 〜 append2R に名前を変えただけ。作業時間は5分くらい。
プロファイラの結果によれば2カ所が遅い。本当に局所的なんですね。

  18          260     229668   (append2R ls1 ls2)                compiler-with-library.scm:5713
   7          110          4   (lambda locals n)                 compiler-with-library.scm:9270
   6           90       4606   pass3/find-free
   5           80     788125   (append2y ls1 ls2)                compiler-with-library.scm:5561

遅い場所のメモ。

1つめ

(define (pass4 lst)
  (pass4/fixup-labels (list->vector (append2R lst '(HALT)))))

これは気づかなかったが言われてみれば如何にも遅そう。

2つ目

これはどうするかなあ。1つめを改善してから考えよう。

(define (pass3/$lambda cb iform locals frees can-frees sets tail)
  (let* ([vars ($lambda.lvars iform)]
         [body ($lambda.body iform)]
         [frees-here (pass3/find-free body
                                      vars
                                      (append2w locals (append2x frees can-frees)))]
         [sets-for-this-lvars (pass3/find-sets body vars)]
         [end-of-closure (make-label)]
         [lambda-cb (make-code-builder)])
    (let1 free-size (if (> (length frees-here) 0)
                        (pass3/collect-free cb frees-here locals frees)
                        0)
      (cput! cb
             'CLOSURE
             (ref-label end-of-closure)
             (length vars)                                            ;; length of arguments
             (> ($lambda.optarg iform) 0)                             ;; optional-arg?
             (length frees-here))                                     ;; number of free variables
      ;; we want to know stack size of lambda body, before emit.
      (let1 body-size (pass3/rec lambda-cb
                                 body
                                 vars
                                 frees-here
                                 (append2y can-frees vars) ;; can-frees and vars don't have common lvars.


今回はこの原始的な方法でうまくいったけど、どこから呼び出されている append2 が遅いかが簡単に分かる方法をプロファイラに仕込みたいなあ。
良い方法あるかな。もしくは別のうまい特定方法とか。