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
Optimization for the ++ operator
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
  7 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
 
José Valim  
View profile  
 More options May 31 2012, 7:55 am
From: José Valim <jose.va...@gmail.com>
Date: Thu, 31 May 2012 13:55:48 +0200
Local: Thurs, May 31 2012 7:55 am
Subject: [erlang-questions] Optimization for the ++ operator

I thought Erlang would optimize the ++ operator when the left side is known
at compile time.

For example, if the compiler sees the following outside of a function
signature:

    "Foo" ++ Bar

It could rewrite it as:

    [$F, $o, $o | assert_list(Bar)]

However, I ran some benchmarks and it seems the optimization does not
happen (on R15B).
With a local dummy implementation of assert_list(Bar), I got that the first
format is 50% slower than the second one.

That said, given the possibility something is odd in my setup, does Erlang
optimize it or not? If not, could it?

*
José Valim
www.plataformatec.com.br
Founder and Lead Developer
*

_______________________________________________
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.
Björn Gustavsson  
View profile  
 More options Jun 1 2012, 4:28 am
From: Björn Gustavsson <bgustavs...@gmail.com>
Date: Fri, 1 Jun 2012 10:28:12 +0200
Local: Fri, Jun 1 2012 4:28 am
Subject: Re: [erlang-questions] Optimization for the ++ operator

On Thu, May 31, 2012 at 1:55 PM, José Valim <jose.va...@gmail.com> wrote:
> I thought Erlang would optimize the ++ operator when the left side is known
> at compile time.

> For example, if the compiler sees the following outside of a function
> signature:

>     "Foo" ++ Bar

> It could rewrite it as:

>     [$F, $o, $o | assert_list(Bar)]

The '++' operator does not verify that the second argument is a list.
Therefore, the compiler will rewrite the first expression to simply:

[$F,$o,$o|Bar]

> However, I ran some benchmarks and it seems the optimization does not happen
> (on R15B).
> With a local dummy implementation of assert_list(Bar), I got that the first
> format is 50% slower than the second one.

Have you made sure that you run each test in a newly spawned process?
Do you run the test for long enough time?

If you have set up your benchmark environment properly, and your second
example is still faster, I can only assume that the code sits better in cache.

--
Björn Gustavsson, Erlang/OTP, Ericsson AB
_______________________________________________
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.
José Valim  
View profile  
 More options Jun 1 2012, 4:46 am
From: José Valim <jose.va...@gmail.com>
Date: Fri, 1 Jun 2012 10:46:28 +0200
Local: Fri, Jun 1 2012 4:46 am
Subject: Re: [erlang-questions] Optimization for the ++ operator

> The '++' operator does not verify that the second argument is a list.
> Therefore, the compiler will rewrite the first expression to simply:

> [$F,$o,$o|Bar]

Yes, thanks. For some weird reason I thought Erlang restricted the right
side to be a list in such cases.

> Have you made sure that you run each test in a newly spawned process?

Do you run the test for long enough time?


Running in a newly spawned process did the trick, the results are now
consistent.
I was already running it 1000 times, here is the code (without using spawn):

https://www.refheap.com/paste/2954

I assume having a "clean" heap (reducing the chance of garbage collection)
is the reason why it is a good idea to run benchmarks in a newly spawned
process?

Thanks Björn!

_______________________________________________
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.
Björn-Egil Dahlberg  
View profile  
 More options Jun 1 2012, 6:07 am
From: Björn-Egil Dahlberg <wallentin.dahlb...@gmail.com>
Date: Fri, 1 Jun 2012 12:07:33 +0200
Local: Fri, Jun 1 2012 6:07 am
Subject: Re: [erlang-questions] Optimization for the ++ operator

1 jun 2012 kl. 10:46 skrev "José Valim" <jose.va...@gmail.com>:

The '++' operator does not verify that the second argument is a list.

> Therefore, the compiler will rewrite the first expression to simply:

> [$F,$o,$o|Bar]

Yes, thanks. For some weird reason I thought Erlang restricted the right
side to be a list in such cases.

> Have you made sure that you run each test in a newly spawned process?

Do you run the test for long enough time?


Running in a newly spawned process did the trick, the results are now
consistent.
I was already running it 1000 times, here is the code (without using spawn):

https://www.refheap.com/paste/2954

I assume having a "clean" heap (reducing the chance of garbage collection)
is the reason why it is a good idea to run benchmarks in a newly spawned
process?

If you want to vary one parameter in a test, make sure all other parameters
stays the same otherwise you have no idea what you are measuring!

Code loading, heaps, position of mars .. Everything has to be taken into
account.

Thanks Björn!

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

_______________________________________________
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.
Gustav Simonsson  
View profile  
 More options Jun 1 2012, 9:09 am
From: Gustav Simonsson <gus...@erlang.org>
Date: Fri, 1 Jun 2012 15:09:09 +0200
Local: Fri, Jun 1 2012 9:09 am
Subject: Re: [erlang-questions] Optimization for the ++ operator

On 2012-06-01 12:07, Bj�rn-Egil Dahlberg wrote:

The effect of Mars magnetic field on that of Earth, even if Earth's
aphelion and the perihelion of Mars were to coincide and the
interplanetary distance were to be at its theoretical minimum, is
negligible compared to the normal variations in Earth's magnetic field.

Therefore it's very unlikely that the relative position of Mars would
affect the probability of a memory bitflip occurring due to cosmic
radiation and thus affecting the benchmark.

Regards,
Gustav Simonsson
Erlang/OTP team

_______________________________________________
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.
Björn-Egil Dahlberg  
View profile  
 More options Jun 1 2012, 9:22 am
From: Björn-Egil Dahlberg <e...@erlang.org>
Date: Fri, 1 Jun 2012 15:22:16 +0200
Local: Fri, Jun 1 2012 9:22 am
Subject: Re: [erlang-questions] Optimization for the ++ operator

On 2012-06-01 15:09, Gustav Simonsson wrote:

My point, in case you missed it, is that you can't disregard something
out of hand. You have to be sure. In physics you might be familiar to
similar topics from dimensional analysis, i.e. how to come up with a
model and how to disregard useless parameters.

All I'm saying is that you should be sure of what you are measuring. =)

_______________________________________________
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.
Heinz N. Gies  
View profile  
 More options Jun 8 2012, 12:25 pm
From: "Heinz N. Gies" <he...@licenser.net>
Date: Fri, 8 Jun 2012 18:25:32 +0200
Local: Fri, Jun 8 2012 12:25 pm
Subject: Re: [erlang-questions] Optimization for the ++ operator

The very unlikely is the important part here ;) also imagine mars position causes it to catch a astroid in it's gravitation field and slingshots it right into your computer - now that would screw your benchmark results!
--
Heinz N. Gies
he...@licenser.net
http://licenser.net

On Jun 1, 2012, at 15:09, Gustav Simonsson wrote:

_______________________________________________
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 »