Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of fasta benchmark #20

Merged
merged 1 commit into from
Apr 8, 2013

Conversation

abeaumont
Copy link
Member

@@ -61,7 +61,7 @@ define variable *last* :: <integer> = 42;
define function gen-random(max-value :: <double-float>)
=> result :: <double-float>;
*last* := modulo((*last* * $ia + $ic), $im);
(max-value * *last*) / $im;
(max-value * *last*) / as(<double-float>, $im);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it would be adding an additional heap allocation ... could something else be done here? How big is the gain from this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No heap allocation is done, since it's a temporary and is not stored.
The improvement comes from the fact that the explicit conversion is done at compile time (just generating a (double)$im) while the implicit conversion is done at runtime and requires additional type checking.
I get a 3x improvement thanks to this change.

Here you can see the generated C codes.
Before:

T2 = TlastTVfasta;
T14 = primitive_cast_integer_as_raw(T2);
T15 = primitive_machine_word_shift_right(T14,2);
T16 = primitive_integer_as_double_float(T15);
T17 = primitive_double_float_as_raw(max_value_);
T18 = primitive_double_float_multiply(T17,T16);
T19 = primitive_raw_as_double_float(T18);
T20_0 = KSVKdMM0I(T19, (D) 559873);
T3_0 = T20_0;
{
  MV_CHECK_TYPE_PROLOGUE(T20_0);
  primitive_type_check(T3_0, &KLdouble_floatGVKd);
  MV_CHECK_TYPE_EPILOGUE();
}
MV_SET_COUNT(1);
return(T3_0);

After:

T2 = TlastTVfasta;
T13 = primitive_cast_integer_as_raw(T2);
T14 = primitive_machine_word_shift_right(T13,2);
T15 = primitive_integer_as_double_float(T14);
T16 = primitive_double_float_as_raw(max_value_);
T17 = primitive_double_float_multiply(T16,T15);
T18 = primitive_double_float_divide(T17,139968.00e0);
T19 = primitive_raw_as_double_float(T18);
T20_0 = T19;
MV_SET_COUNT(1);
return(T20_0);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes, I forget just how smart Open Dylan's compiler is.

Thanks!

waywardmonkeys added a commit that referenced this pull request Apr 8, 2013
Improve performance of fasta benchmark
@waywardmonkeys waywardmonkeys merged commit 701ce67 into dylan-lang:master Apr 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants