From: Nathan F. <fr...@gm...> - 2007-06-05 15:08:28
|
On 6/5/07, Nikodemus Siivola <nik...@ra...> wrote: > I wonder is if using a small memoization cache would help -- obviously > it would help with the "print PI in a loop" test FWIW, a profile of "print a million random single-floats" with current SBCL looks like: Self Total Cumul Nr Count % Count % Count % Calls Function ------------------------------------------------------------------------ 1 33 13.5 33 13.5 33 13.5 - SB-VM::GENERIC-+ 2 31 12.7 84 34.4 64 26.2 - SB-IMPL::FLONUM-TO-DIGITS 3 28 11.5 44 18.0 92 37.7 - SB-IMPL::OUTPUT-BYTES/UTF-8 4 22 9.0 65 26.6 114 46.7 - SB-IMPL::FD-SOUT 5 21 8.6 21 8.6 135 55.3 - TRUNCATE Everything else is < 4%. Eliminating the first two will likely involve some careful analysis and inserting declarations in FLONUM-TO-DIGITS. Eliminating the second two may be simpler: there is a FIXME in FD-SOUT: (and (find #\newline thing :start start :end end) ;; FIXME why do we need both calls? ;; Is find faster forwards than ;; position is backwards? (position #\newline thing :from-end t :start start :end end))))) Surely we don't need to have both calls, do we? Just calling POSITION should work fine, right? There is also this clever optimization: (if (and (typep thing 'base-string) (eq (fd-stream-external-format stream) :latin-1)) (ecase (fd-stream-buffering stream) (:full (output-raw-bytes stream thing start end)) (:line (output-raw-bytes stream thing start end) (when last-newline (flush-output-buffer stream))) (:none (frob-output stream thing start end nil))) ;;; ...actually do external-format conversion It seems that another win would be to check for :utf-8 or whatever and try to send base-strings when printing floats (FLONUM-TO-DIGITS does this, but FLONUM-TO-STRING may not). Doing this extra check might also speed up other code that is careful about outputting base-strings. (It is also yet another reason to implement real base-char string-streams...) Do these sound reasonable? -Nathan |