cache loaded compiled modules

using a SHA1 hash stored in the marshaled bytecode; this cache
 lowers the cost of sandboxes or other uses of multiple namespaces
 when the code inspector doesn't change; the caching is almost
 transparent, but an eval handler might be called with compiled
 code that cannot be written

original commit: 97ce26b182
This commit is contained in:
Matthew Flatt 2011-04-16 08:02:14 -06:00
commit b3fd71415d
4 changed files with 12 additions and 3 deletions

View File

@ -16,6 +16,8 @@
(define assume-primitives (make-parameter #t)) (define assume-primitives (make-parameter #t))
(define worker-count (make-parameter 1)) (define worker-count (make-parameter 1))
(define mzc-symbol (string->symbol (short-program+command-name)))
(define source-files (define source-files
(command-line (command-line
#:program (short-program+command-name) #:program (short-program+command-name)
@ -67,9 +69,9 @@
(printf " making ~s\n" (path->string p))))]) (printf " making ~s\n" (path->string p))))])
(for ([file source-files]) (for ([file source-files])
(unless (file-exists? file) (unless (file-exists? file)
(error 'mzc "file does not exist: ~a" file)) (error mzc-symbol "file does not exist: ~a" file))
(set! did-one? #f) (set! did-one? #f)
(let ([name (extract-base-filename/ss file 'mzc)]) (let ([name (extract-base-filename/ss file mzc-symbol)])
(when (verbose) (when (verbose)
(printf "\"~a\":\n" file)) (printf "\"~a\":\n" file))
(parameterize ([compile-context-preservation-enabled (parameterize ([compile-context-preservation-enabled

View File

@ -19,6 +19,8 @@
(define plt-setup-collections (make-parameter null)) (define plt-setup-collections (make-parameter null))
(define plt-include-compiled (make-parameter #f)) (define plt-include-compiled (make-parameter #f))
(define mzc-symbol (string->symbol (short-program+command-name)))
(define-values (plt-output source-files) (define-values (plt-output source-files)
(command-line (command-line
#:program (short-program+command-name) #:program (short-program+command-name)
@ -53,7 +55,7 @@
(begin (begin
(for ([fd source-files]) (for ([fd source-files])
(unless (relative-path? fd) (unless (relative-path? fd)
(error 'mzc (error mzc-symbol
"file/directory is not relative to the current directory: \"~a\"" "file/directory is not relative to the current directory: \"~a\""
fd))) fd)))
(pack-plt plt-output (pack-plt plt-output

View File

@ -127,6 +127,8 @@
(write-bytes (bytes (bytes-length version-bs)) outp) (write-bytes (bytes (bytes-length version-bs)) outp)
(write-bytes version-bs outp) (write-bytes version-bs outp)
; Write empty hash code
(write-bytes (make-bytes 20 0) outp)
; Write the symbol table information (size, offsets) ; Write the symbol table information (size, offsets)
(define symtabsize (add1 (vector-length symbol-table))) (define symtabsize (add1 (vector-length symbol-table)))

View File

@ -1012,6 +1012,9 @@
(define version (read-bytes (min 63 (read-byte port)) port)) (define version (read-bytes (min 63 (read-byte port)) port))
;; Skip module hash code
(read-bytes 20 port)
(define symtabsize (read-simple-number port)) (define symtabsize (read-simple-number port))
(define all-short (read-byte port)) (define all-short (read-byte port))