Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions,...

37
Optimizing Perl programs Alex Burzyński Thames Valley Perl Mongers 20 th March 2012

Transcript of Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions,...

Page 1: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing Perl programsAlex Burzyński

Thames Valley Perl Mongers20th March 2012

Page 2: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing is fun:

Page 3: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing is fun:

➔ Feels like beating world records

Page 4: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing is fun:

➔ Feels like beating world records

➔ It's relatively easy

Page 5: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing is fun:

➔ Feels like beating world records

➔ It's relatively easy

• tons of “fast templating systems”

Page 6: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing is fun:

➔ Feels like beating world records

➔ It's relatively easy

• tons of “fast templating systems”

➔ Refactoring for “experts”

Page 7: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Important part is to get

maximum results with

minimum effort

Page 8: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Where to start?

➔ Get your app working first...

Page 9: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Where to start?

➔ Get your app working first...

• unit tests (Devel::Cover)

Page 10: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel
Page 11: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel
Page 12: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Where to start?

➔ Get your app working first...

• unit tests (Devel::Cover)

➔ Gather lots of real-life input data

Page 13: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Where to start?

➔ Get your app working first...

• unit tests (Devel::Cover)

➔ Gather lots of real-life input data

• avoid optimizing for rare events

Page 14: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Where to start?

➔ Get your app working first...

• unit tests (Devel::Cover)

➔ Gather lots of real-life input data

• avoid optimizing for rare events

➔ Profile!

Page 15: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Profiling

➔ Development – Devel::NYTProf

Page 16: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Profiling

➔ Development – Devel::NYTProf

• Line, subroutine and block profiles

Page 17: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel
Page 18: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Profiling

➔ Development – Devel::NYTProf

• Line, subroutine and block profiles

• HTML reports (treemaps, links to

source code)

Page 19: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel
Page 20: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Profiling

➔ Development – Devel::NYTProf

• Line, subroutine and block profiles

• HTML reports (treemaps, links to

source code)

• Call-graphs via Kcachegrind

(relationships between subroutines)

Page 21: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel
Page 22: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Profiling

➔ Production – DashProfiler

Page 23: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Profiling

➔ Production – DashProfiler

• Continuous monitoring

Page 24: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Profiling

➔ Production – DashProfiler

• Continuous monitoring

• Flexible configuration

Page 25: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Profiling

➔ Production – DashProfiler

• Continuous monitoring

• Flexible configuration

Page 26: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Profiling

➔ Production – DashProfiler

• Continuous monitoring

• Flexible configuration

• Minimal code changes

Page 27: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel
Page 28: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing

➔ Cache

Page 29: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing

➔ Cache

• functions

Page 30: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing

➔ Cache

• functions, variables

Page 31: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing

➔ Cache

• functions, variables, DBI's *_cached

Page 32: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing

➔ Cache

• functions, variables, DBI's *_cached

➔ Refactor (B::Concise + B::Deparse)

and Benchmark

Page 33: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel
Page 34: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing

➔ Cache

• functions, variables, DBI's *_cached

➔ Refactor (B::Concise + B::Deparse)

and Benchmark

➔ Parallel execution

Page 35: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing

➔ Cache

• functions, variables, DBI's *_cached

➔ Refactor (B::Concise + B::Deparse)

and Benchmark

➔ Parallel execution

➔ Event-based programming

Page 36: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Optimizing

➔ Cache

• functions, variables, DBI's *_cached

➔ Refactor (B::Concise + B::Deparse)

and Benchmark

➔ Parallel execution

➔ Event-based programming

➔ Rewrite in C – Perl XS

Page 37: Optimizing Perl programs...2013/03/17  · Event-based programming Optimizing Cache • functions, variables, DBI's *_cached Refactor (B::Concise + B::Deparse) and Benchmark Parallel

Questions?