Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dist::Zilla::Plugins:: Best Practices

Dist::Zilla::Plugins:: Best Practices

You've already written your own Dist::Zilla plugin (or you plan to write one)? Your dzil build are slow and you want to know why? This is for you.

In this talk I will expose a few tips that will help you to avoid adding more bloat to Dist::Zilla:
- how to discover performance issues (tools...)
- how to write efficient InlineFiles-based Test:: plugin
- best pratices to inject dependencies

9a029d2d948f128443f996fa12b3d3a1?s=128

Olivier Mengué

August 22, 2014
Tweet

More Decks by Olivier Mengué

Other Decks in Programming

Transcript

  1. August 22th, 2014 YAPC::EU::2014 Dist::Zilla::Plugin:: Best Practices for authors

  2. Olivier Mengué DOLMEN - @omengue • IoT software engineer at

    IJENKO • Perl embeded in a gateway between a Home Area Network (HAN) and the Internet ; ZigBee, M-Bus, EnOcean… • Member of the Perl Toolchain Gang • Open Source: – 20+ dists on CPAN – 300+ tickets filled on rt.cpan.org ; – Maintainer of LiquidPrompt github:nojhan/liquidprompt – Personal projects : github-keygen, angel-PS1 – 72 commits in Dist::Zilla core (committer #3)
  3. Plan • dzil plugins overview • Profiling your build •

    Advices
  4. Dist::Zilla plugins • Dist::Zilla::Plugin::* – Plugins referenced from dist.ini –

    Methods called during « phases » – dist.ini: [Name] • Dist::Zilla::Plugin::Test::* – Plugins that inject files test scripts in t/ or xt/ • Dist::Zilla::PluginBundle::* – Group of plugins, with settings, packaged – dist.ini: [@Name] • Dist::Zilla::App::Command::* – For dzil sub commands
  5. dzil performance : profiling • List modules loaded by dzil

    perl ­d:TraceUse=output:out.txt ­S dzil nop • Check dzil run flamegraph to find major hot spots perl ­d:NYTProf ­S dzil listdeps nytprofhtml ­­open
  6. dzil profiling dzil nop dzil listdeps dzil build dzil test

  7. ?? POLL ?? How many modules are loaded by dzil

    nop for [@Milla] Dist::Milla is bundle that provides a useful set of plugins. Reply is system dependent as it depends on plugins installed.
  8. 543

  9. ...but down from 672 with my patches https://github.com/miyagawa/Dist-Milla/issues/24

  10. Solution: lazy loading Replace... with... use Foo::Bar; sub foo {

    my $foo = Foo::Bar­>new; } sub foo { require Foo::Bar; my $foo = Foo::Bar­>new; } use Foo::Bar qw< bar >; sub foo { bar(…); } sub foo { require Foo::Bar; Foo::Bar::bar(…); }
  11. Dist::Zilla::App::Command::* • All plugins are loaded every time you run

    'dzil', whatever the command • Impacts all builds of all your projects • Fix : delay loading of dependencies to the execute method
  12. Dist::Zilla::Plugin::* • Executed by phase (see Dist::Zilla::App::Command::dumpphases) • But loaded

    always • Delay dependencies loading!
  13. Dist::Zilla::Plugin::* • Use your plugin for the build of the

    distribution of the plugin – Eat your own dog food – Find issues early – Just building the dist is one more test! • How to: – Use the plugin in dist.ini – But use [Bootstrap::lib] before else you use the last installed one in @INC, not the one in development
  14. Dist::Zilla::Plugin::* • Since dzil v5 ->content vs ->encoded_content

  15. Dist::Zilla::Plugin::Test::* • If the generated script uses a module, inject

    the module as a prereq so it appears in dzil listdeps ­­author – Author, release tests must inject as 'develop' prereq – Others tests as 'test' prereq • The test script must fail (loudly) if the prereq is missing – « Soft failure » (skip the test if prereq missing) is a failure of the plugin author as that makes the plugin useless • How to: – Use Dist::Zilla::Role::PrereqSource – Example: Dist::Zilla::Plugin::Test::NoTabs
  16. Dist::Zilla::PluginBundle::* • Eat your own dog food … after [Bootstrap::lib]

    • Use Dist::Zilla::Role::PluginBundle::PluginRemover – Convenient for users of the bundle
  17. Summary • As a dzil user, profile your own builds,

    report issues to plugin authors • As a plugin author, delay dependency loading
  18. Questions? dolmen@cpan.org Twitter: @omengue IRC: dolmen in #distzilla Slides :

    not yet on... http://o.mengue.free.fr/presentations/ Https://speakerdeck.com/dolmen