[racket] Web-cells, anonymous functions, and garbage collection
Good evening,
I've been investigating lang web-server, performance and garbage
collection
I have a question regarding anonymous functions and web cells
Examples below require:
#lang web-server
(require racket/serialize
web-server/lang/web-cells)
Constants appear serializable by their value being explicitly written
out
For example,
(serialize 'this-is-a-song-about-japan)
;-> '((3) 0 () 0 () () this-is-a-song-about-japan)
Whereas anonymous functions appear serializable by the mechanism of
being "lifted" (i.e. reified) to a module level binding
For example
(serialize (λ (x) x))
;-> '((3) 1 (('anonymous-module . "lifted.1386")) 0 () () (0))
Moving the discussion to web-cells
(define wc-constant (make-web-cell #f))
(define wc-anonymous (make-web-cell #f))
(web-cell-shadow wc-constant 'this-is-a-song-about-Japan)
(web-cell-shadow wc-anonymous (λ (x) x))
(printf " wc-constant: ~A\n wc-anonymous: ~A\n"
(serialize wc-1)
(serialize wc-2))
returns
wc-constant: ((3) 1 (((lib web-server/lang/web-cells.rkt) .
deserialize-info:primitive-wc-v0)) 0 () () (0 lifted.1534-0))
wc-anonymous: ((3) 1 (((lib web-server/lang/web-cells.rkt) .
deserialize-info:primitive-wc-v0)) 0 () () (0 lifted.1570-1))
While now both values are 'lifted' (i.e. reified), a close examination
of the URL-string sent back to a client after send/suspend/dispatch
reveals that, with respect to the constant, lifted.1534 appears to be
explicitly represented, elsewhere in the string as an associative pair
i.e. (lifted.1534 this-is-a-song-about-Japan)
whereas for the anonymous function, its not clear that its reference,
lifted.1570 is explicitly represented
Which leads me to wonder about whether the reference to the anonymous
function, lifted.1570, is being maintained on the server,
And if so, how is it being garbage collected, as its impossible to ever
determine that it is unreachable.
I will also point out that prior to a year ago, anonymous functions
failed the serializability predicate. (serializable? anon-func) -> #f. I
can pull out the correspondence/background related to that if desirable.
I apologize if I'm just misreading the data.
Here's the complete example,with a stateless web server. Note that when
you inspect the url-string**for the datum this-is-a-song-about-Japan,
its there, but when looking for the datum more-distinctive-text, its not
present in the url-string.
**right click on the link, then copy/paste, or click the 'click-me' link
and copy/paste the URL from the address bar)
Thanks very much.
Thanks again.
#lang web-server
(require web-server/servlet-env)
(define wc-constant (make-web-cell #f))
(define wc-anonymous (make-web-cell #f))
(web-cell-shadow wc-constant 'this-is-a-song-about-Japan)
(web-cell-shadow wc-anonymous (λ (x) 'more-distinctive-text))
(define (start request)
(letrec ((response-generator (λ (make-url)
(response/xexpr `(html (head)
(body (a ((href
,(format "~A" (make-url receive-request)))) "click me"))))))
(receive-request (λ (request)
(response/xexpr `(html (head)
(body "Thank you.
We are done."))))))
(send/suspend/dispatch response-generator)))
(serve/servlet start
#:stateless? #t
#:launch-browser? #t
#:connection-close? #t
#:quit? #f
#:listen-ip #f
#:port 8000
#:servlet-path "/")
Thanks much.
Zack