OT? -NO! Essay: Programming as if Performance Mattered
Fri May 7 10:17:45 CEST 2004
Hehe :-) how does it feel to be flamebait James?
After reading the article, I had a poke around for myself, and found
this in lists.erl (R9C) which made me curious:
%% reverse(L) reverse all elements in the list L. Is now a BIF!
reverse( = L) ->
reverse([_] = L) ->
reverse([A, B]) ->
reverse([A, B | L]) ->
lists:reverse(L, [B, A]).
Is it a BIF, or is it not? What is the purpose of these four
clauses? Surely the BIF should handle these cases, or is this a tweak
for optimisation? How does Erlang know to call this definition of
lists:reverse/1 in lists.erl instead of the BIF definition?
Another thing in http://www.dadgum.com/james/shootout.html mentioned the
cost of inter-module calls, where replacing lists:append/2 with ++.
Surely this cost must be vanishingly small, specially if the module is
loaded and ready to go?
And a third: "Changing element 50 of a 1,000,000 element tuple results
in a new 1,000,000 element tuple." I've written some code to seek and
replace tagged tuples in a tree-like Erlang term by following a path
defined as a list of tag atoms which lead to the tagged tuple to
Is there a way I can represent a potentially large term in a way that
avoids copying the whole term for each replacement e.g. using ets to
represent the tree allowing in-place changes, followed by recreating the
whole modified term when modifications are finished?
Or maybe I should write an algorithm that makes multiple modifications
in a single sweep...
It's Friday. Maybe I need to relax and try not to worry! :-)
On Fri, 07 May 2004 10:20:00 +1200
Kurt at DBC <kurtw@REDACTED> wrote:
> Roger Larsson wrote:
> > http://www.dadgum.com/james/performance.html
> > http://developers.slashdot.org/developers/04/05/06/032213.shtml?tid=126&tid=156
> > /RogerL
> D'oh beaten!
> And thanks James, a good read.
> How does it feel to be /.famous ? (:
> Cheers, Kurt.
"The Tao of Programming
flows far away
on the wind of morning."
More information about the erlang-questions