4
4
5
5
= SUBTITLE Measuring and improving run-time or compile-time performance
6
6
7
- A simple take on performance is "speed and ram usage". According to wikipedia,
8
- L < Computer Performance|https://en.wikipedia.org/wiki/Computer_Performance > is
9
- "characterized by the amount of useful work accomplished by a computer system or
10
- computer network compared to the time and resources used.".
7
+ This page is about anything to do with L < computer performance|https://en.wikipedia.org/wiki/Computer_Performance >
8
+ in the context of Perl 6.
11
9
12
10
= head1 First, clarify the problem
13
11
@@ -65,7 +63,7 @@ Use L<perl6-bench|https://github.com/japhb/perl6-bench>.
65
63
If you run perl6-bench for multiple compilers (typically versions of Perl 5, Perl 6, or NQP)
66
64
then results for each are visually overlaid on the same graphs to provide for quick and easy comparison.
67
65
68
- = head2 Share the problem
66
+ = head2 Share problems
69
67
70
68
Once you've used the above techniques to pinpoint code and performance that really matters you're in
71
69
a good place to share problems, one at a time:
@@ -79,7 +77,7 @@ What if it took a month for folk to help you achieve that? A year?
79
77
80
78
= item Let folk know if your Perl 6 use-case is in a production setting or just for fun.
81
79
82
- = head1 Solve the problem
80
+ = head1 Solve problems
83
81
84
82
This bears repeating: B < make sure you're not wasting time on the wrong code > .
85
83
Start by identifying the L < "critical 3%"|https://en.wikiquote.org/wiki/Donald_Knuth > of your code.
@@ -104,11 +102,12 @@ The call overhead of having multiple C<foo> definitions is generally insignifica
104
102
of C < where > below), so if your new definition handles its particular case more quickly/leanly than the
105
103
previously existing set of definitions then you probably just made your code that much faster/leaner for that case.
106
104
107
- = head2 Type -checks and call resolution
105
+ = head2 Speed up type -checks and call resolution
108
106
109
107
Most L < C < where > clauses|/type/Signature#Type_Constraints> -- and thus most
110
- L < subtypes|http://design.perl6.org/S12.html#Types_and_Subtypes > -- force dynamic (run-time)
111
- type checking and call resolution. This is slower, or at least later, than compile-time.
108
+ L < subsets|http://design.perl6.org/S12.html#Types_and_Subtypes > -- force dynamic (run-time)
109
+ type checking and call resolution for any call it I < might > match. This is slower, or at least later,
110
+ than compile-time.
112
111
113
112
Method calls are generally resolved as late as possible, so dynamically, at run-time,
114
113
whereas sub calls are generally resolvable statically, at compile-time.
@@ -156,15 +155,15 @@ A "lazy" approach often performs much better:
156
155
157
156
This loop pulls just one line from 'largefile.txt', immediately processes it, then gets the next, and so on.
158
157
159
- = head3 Changing sequential/blocking code to parallel/non-blocking
158
+ = head3 Change sequential/blocking code to parallel/non-blocking
160
159
161
160
This is another very important class of algorithmic improvement.
162
161
163
162
See the slides for
164
163
L < Parallelism, Concurrency, and Asynchrony in Perl 6|http://jnthn.net/papers/2015-yapcasia-concurrency.pdf#page=17 >
165
164
and/or L < the matching video|https://www.youtube.com/watch?v=JpqnNCx7wVY&list=PLRuESFRW2Fa77XObvk7-BYVFwobZHdXdK&index=8 > .
166
165
167
- = head2 Using native types
166
+ = head2 Use native types
168
167
169
168
You may be able to make some code run faster and/or use less ram by adding native types to your code:
170
169
@@ -176,7 +175,7 @@ XXX Start of section to be written
176
175
177
176
XXX End of section to be written
178
177
179
- = head2 Using existing high performance code
178
+ = head2 Use existing high performance code
180
179
181
180
Is there an existing high (enough) performance implementation of what you're trying to speed up / slim down?
182
181
@@ -193,11 +192,12 @@ L<use Perl 5 modules in Perl 6|http://stackoverflow.com/a/27206428/1077672>.
193
192
More generally, Perl 6 is designed to be able to smoothly interop with other languages and there are a number
194
193
of L < modules aimed at providing convenient use of libs from other langs|http://modules.perl6.org/#q=inline > .
195
194
196
- = head2 Speeding up Rakudo itself
195
+ = head2 Make the Rakudo compiler generate faster code
197
196
198
- The focus to date (Feb 2016) regarding the compiler has been correctness, not speed, but that's expected to
199
- change somewhat this year and beyond. You can talk to compiler devs on the freenode IRC channels #perl6 and
200
- #moarvm about what to expect. Or you can contribute yourself:
197
+ The focus to date (Feb 2016) regarding the compiler has been correctness, not how fast it generates code or,
198
+ more importantly, how fast or lean the code it generates runs. But that's expected to change somewhat this
199
+ year and beyond. You can talk to compiler devs on the freenode IRC channels #perl6 and #moarvm about what
200
+ to expect. Better still you can contribute yourself:
201
201
202
202
= item Rakudo is largely written in Perl 6. So if you can write Perl 6, then you can hack on the compiler,
203
203
including optimizing any of the large body of existing high-level code that impacts the speed of your code
0 commit comments