Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Question about implementation
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Max Lapshin  
View profile  
 More options Sep 10 2012, 10:27 am
From: Max Lapshin <max.laps...@gmail.com>
Date: Mon, 10 Sep 2012 18:27:20 +0400
Local: Mon, Sep 10 2012 10:27 am
Subject: [erlang-questions] Question about implementation
For example I have such gen_server:

-record(state,
   field1,
   field2,
   field3,
   counter = 0

}.

handle_info(incr, #state{counter = Counter} = State) ->
   {noreply, State#state{counter = Counter + 1}};

Will here whole #state{} be deep-copied with new Counter +1 field, or
it is possible to guess, that here optimization is possible and just
"edit" counter field in existing tuple?

Is it possible to understand by erlang source code, that State is no
longer referenced anywhere to avod large allocation and free?
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lukas Larsson  
View profile  
 More options Sep 10 2012, 12:08 pm
From: Lukas Larsson <lu...@erlang-solutions.com>
Date: Mon, 10 Sep 2012 18:08:26 +0200
Local: Mon, Sep 10 2012 12:08 pm
Subject: Re: [erlang-questions] Question about implementation
Hello,

Only the tuple which is the record and the immidiates (i.e. small int,
atom, pid, ref etc) will be copied. All other parts use pointers
internally and the same pointers will be copied into the correct
places within the tuple. So in this case a new 6 word memory block
will be created and filled with the atom undefined and finally the new
counter.

I think that the compiler does some optimization based on updating
tuples within the same function body, though I've forgotten what it is
it does.

Hope that makes sense.

Lukas

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Max Lapshin  
View profile  
 More options Sep 10 2012, 12:14 pm
From: Max Lapshin <max.laps...@gmail.com>
Date: Mon, 10 Sep 2012 20:14:22 +0400
Local: Mon, Sep 10 2012 12:14 pm
Subject: Re: [erlang-questions] Question about implementation
On Mon, Sep 10, 2012 at 8:08 PM, Lukas Larsson

<lu...@erlang-solutions.com> wrote:
> Hello,

> Only the tuple which is the record and the immidiates (i.e. small int,
> atom, pid, ref etc) will be copied. All other parts use pointers
> internally and the same pointers will be copied into the correct
> places within the tuple. So in this case a new 6 word memory block
> will be created and filled with the atom undefined and finally the new
> counter.

Thank you!

It is right what I wanted to hear. No deep copy, only reallocation of
top-level tuple.
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Dormont  
View profile  
 More options Sep 10 2012, 1:35 pm
From: Daniel Dormont <d...@greywallsoftware.com>
Date: Mon, 10 Sep 2012 13:35:18 -0400
Local: Mon, Sep 10 2012 1:35 pm
Subject: Re: [erlang-questions] Question about implementation

On Mon, Sep 10, 2012 at 12:08 PM, Lukas Larsson
<lu...@erlang-solutions.com>wrote:

> Hello,

> Only the tuple which is the record and the immidiates (i.e. small int,
> atom, pid, ref etc) will be copied. All other parts use pointers
> internally and the same pointers will be copied into the correct
> places within the tuple. So in this case a new 6 word memory block
> will be created and filled with the atom undefined and finally the new
> counter.

> I think that the compiler does some optimization based on updating
> tuples within the same function body, though I've forgotten what it is
> it does.

This bit?
http://www.erlang.org/doc/efficiency_guide/commoncaveats.html#id61731

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Max Lapshin  
View profile  
 More options Sep 10 2012, 1:36 pm
From: Max Lapshin <max.laps...@gmail.com>
Date: Mon, 10 Sep 2012 21:36:06 +0400
Local: Mon, Sep 10 2012 1:36 pm
Subject: Re: [erlang-questions] Question about implementation

Exactly! Thanks.
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard O'Keefe  
View profile  
 More options Sep 10 2012, 5:53 pm
From: "Richard O'Keefe" <o...@cs.otago.ac.nz>
Date: Tue, 11 Sep 2012 09:53:41 +1200
Local: Mon, Sep 10 2012 5:53 pm
Subject: Re: [erlang-questions] Question about implementation

On 11/09/2012, at 2:27 AM, Max Lapshin wrote:

> Will here whole #state{} be deep-copied with new Counter +1 field,

No it will be *shallow*-copied.  You get a new #state term, but
any fields that are not changed will not themselves be copied.

> or
> it is possible to guess, that here optimization is possible and just
> "edit" counter field in existing tuple?

> Is it possible to understand by erlang source code, that State is no
> longer referenced anywhere to avod large allocation and free?

For the special case of states passed around loops of private functions
it ought to be possible to infer that a function argument is not shared
but for exported functions it is not possible because it depends on the
callers.

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Loïc Hoguin  
View profile  
 More options Sep 14 2012, 7:46 pm
From: Loïc Hoguin <es...@ninenines.eu>
Date: Sat, 15 Sep 2012 01:45:58 +0200
Local: Fri, Sep 14 2012 7:45 pm
Subject: Re: [erlang-questions] Question about implementation
Hello,

On 09/10/2012 07:35 PM, Daniel Dormont wrote:

Is the optimization applied automatically to records?

--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Virding  
View profile  
 More options Sep 16 2012, 5:10 pm
From: Robert Virding <robert.vird...@erlang-solutions.com>
Date: Sun, 16 Sep 2012 22:10:33 +0100 (BST)
Local: Sun, Sep 16 2012 5:10 pm
Subject: Re: [erlang-questions] Question about implementation
Yes. There are a few rules which need to be followed so that the compiler can safely do this optimisation, and generally doing multiple updates to a record *in one go* will satisfy these rules. So

X1 = X0#r{a=foo(),b=bar(),c=baz()},

will be optimised, while

X1 = X0#r{a=foo()},
X2 = X1#r{b=bar()},
X3 = X2#r{c=baz()},

will not. It always tries to do this optimisation but it is generally seldom safe to do it.

Robert

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »