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

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

    View Slide

  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)

    View Slide

  3. Plan

    dzil plugins overview

    Profiling your build

    Advices

    View Slide

  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

    View Slide

  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

    View Slide

  6. dzil profiling
    dzil nop
    dzil listdeps
    dzil build
    dzil test

    View Slide

  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.

    View Slide

  8. 543

    View Slide

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

    View Slide

  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(…);
    }

    View Slide

  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

    View Slide

  12. Dist::Zilla::Plugin::*

    Executed by phase (see
    Dist::Zilla::App::Command::dumpphases)

    But loaded always

    Delay dependencies loading!

    View Slide

  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

    View Slide

  14. Dist::Zilla::Plugin::*

    Since dzil v5
    ->content vs ->encoded_content

    View Slide

  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

    View Slide

  16. Dist::Zilla::PluginBundle::*

    Eat your own dog food
    … after [Bootstrap::lib]

    Use
    Dist::Zilla::Role::PluginBundle::PluginRemover
    – Convenient for users of the bundle

    View Slide

  17. Summary

    As a dzil user, profile your own builds, report
    issues to plugin authors

    As a plugin author, delay dependency loading

    View Slide

  18. Questions?
    [email protected]
    Twitter: @omengue
    IRC: dolmen in #distzilla
    Slides : not yet on...
    http://o.mengue.free.fr/presentations/
    Https://speakerdeck.com/dolmen

    View Slide