[web-devel] Caching the System time

Greg Weber greg at gregweber.info
Sat Aug 6 21:17:37 CEST 2011


extra bonus points: use Kazu's http-date package [1]. Actually, from Kazu's
reports most of the benefit from the caching is likely due to avoiding
creating the string with haskell's current date libraries.

[1]
http://hackage.haskell.org/packages/archive/http-date/0.0.0/doc/html/Network-HTTP-Date.html

On Sat, Aug 6, 2011 at 11:11 AM, Michael Snoyman <michael at snoyman.com>wrote:

> Without having delved into the issue in any great depth, I had a
> possible idea on this point. How about storing an IORef containing a
> time and the text representations you need. Whenever you need to get
> the time, compare the time in the IORef with the current time, and if
> they're different, update appropriately. Bonus points: store in an
> unpacked datatype and use a Builder instead of String. Would this (in
> theory) work?
>
> On Sat, Aug 6, 2011 at 7:18 PM, Gregory Collins <greg at gregorycollins.net>
> wrote:
> > FWIW: we don't cache the system time because it's slow to *get* it -- we
> > cache it because it's slow to turn it into a text string (for HTTP
> > responses, logging, etc). It still may be a stupid thing to do, but it
> > benchmarked faster when I wrote it.
> > G
> >
> > On Fri, Aug 5, 2011 at 7:47 PM, Bryan O'Sullivan <bos at serpentine.com>
> wrote:
> >>
> >> On Fri, Aug 5, 2011 at 7:57 AM, Greg Weber <greg at gregweber.info> wrote:
> >>>
> >>> We are finally getting around to implementing a robust logging solution
> >>> within Yesod. This creates the issue of having to frequently access the
> >>> system time. I see that Snap has a separate thread to get the system
> time
> >>> and cache the result [1].
> >>
> >> That is an absurd non-optimisation. It costs just a few dozen
> nanoseconds
> >> to get the time of day under OS X, and Linux should be even cheaper
> since it
> >> doesn't involve a system call. It wouldn't surprise me if the approach
> above
> >> is actually slower.
> >> _______________________________________________
> >> web-devel mailing list
> >> web-devel at haskell.org
> >> http://www.haskell.org/mailman/listinfo/web-devel
> >>
> >
> >
> >
> > --
> > Gregory Collins <greg at gregorycollins.net>
> >
> > _______________________________________________
> > web-devel mailing list
> > web-devel at haskell.org
> > http://www.haskell.org/mailman/listinfo/web-devel
> >
> >
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110806/71c3b7d8/attachment.htm>


More information about the web-devel mailing list