<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>yko</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/yko/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/yko/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/yko//716</id>
    <updated>2013-05-03T20:19:40Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>It&apos;s time to admit I&apos;ve failed</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/yko/2013/05/its-time-to-admit-ive-failed.html" />
    <id>tag:blogs.perl.org,2013:/users/yko//716.4643</id>

    <published>2013-05-03T18:36:09Z</published>
    <updated>2013-05-03T20:19:40Z</updated>

    <summary>Two days ago I was so excited! I had an idea how to make the Perl world a bit better, faster and simpler. Of course, I didn’t spread such exciting news until I checked and double-checked and benchmarked, until I’m...</summary>
    <author>
        <name>yko</name>
        <uri>http://korshak.name</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/yko/">
        <![CDATA[<p>Two days ago I was so excited! I had an idea how to make the Perl world a bit better, faster and simpler. Of course, I didn’t spread such exciting news until I checked and double-checked and benchmarked, until I’m absolutely sure I’ve found The Holy Grail.</p>

<p>Well, see the title. It hurts. All my benchmarks contained a terrible mistake. And those +20%, or, maybe even +100% speed boost PugiXML interface could provide doesn’t worth all the buzz I created.</p>

<p>I apologize.</p>]]>
        <![CDATA[<p>Yet, Perl interface to PugiXML I’ve described in my previous post could be (optimistically) twice as fast as LibXML. In some cases. But I’m so disappointed by my failure that I just don’t think it worth it.</p>

<p>Another lesson learned.</p>

<p>When you feel lack of speed with HTML parsing please use something LibXML based, like HTML::TreeBuilder::LibXML or just XML::LibXML. Just make sure you are using load_html() family instead of load_xml() and enable recover() mode as it’s done in <a href="https://metacpan.org/source/TOKUHIROM/HTML-TreeBuilder-LibXML-0.17/lib/HTML/TreeBuilder/LibXML.pm#L36">HTML::TreeBuilder::LibXML</a></p>

<p>For those who still are interested, the code of the prototype is published at <a href="https://github.com/yko/pugixml-perl">https://github.com/yko/pugixml-perl</a><br />
At some point I may decide to continue development. Unfortunately it would not be that lightning fast as initially expected.</p>]]>
    </content>
</entry>

<entry>
    <title>[FAILED] 10x faster than LibXML</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/yko/2013/05/tldr-thing-that-parses-html.html" />
    <id>tag:blogs.perl.org,2013:/users/yko//716.4635</id>

    <published>2013-05-01T15:45:03Z</published>
    <updated>2013-05-03T20:25:32Z</updated>

    <summary>Unfortunately, the idea contained fatal flaw. See the following post for explaantions. Once upon a time I faced a huge pile of HTML files which I had to analyze. Say, there were about 1 000 000 of them. Say, 100...</summary>
    <author>
        <name>yko</name>
        <uri>http://korshak.name</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/yko/">
        <![CDATA[<p>Unfortunately, the idea contained fatal flaw. See <a href="http://blogs.perl.org/users/yko/2013/05/its-time-to-admit-ive-failed.html">the following post</a> for explaantions. </p>

<p>Once upon a time I faced a huge pile of HTML files which  I had to analyze. Say, there were about 1 000 000 of them. Say, 100 Gb of data.<br />
Most of you would say “It’s not that much!”. And you are right. It’s not.</p>

<p>But then I’ve decided to estimate time required to process that pile of files. I quickly put XPaths of what I was needed together and got a prototype in <a href="https://metacpan.org/module/Web::Scraper">Web::Scraper</a>. And here I go: ~0.94s per file, i/o overhead not included. That occurred more than 11 days on my laptop. Phew!</p>]]>
        <![CDATA[<p>Well, thanks to CPAN and you guys, we have a drop-in replacement that switches to LibXML - <a href="https://metacpan.org/module/Web::Scraper::LibXML">Web::Scraper::LibXML</a>. I’ve got ~0.17, which were only about two days. That was too much for me anyway and I decided to try something more exotic.</p>

<p>I’ve googled a list of available HTML C/C++ parsers, went through their benchmarks, documentation and requirements and I’ve decided that I like <a href="http://pugixml.org/">pugixml</a> library.</p>

<p>Yep, I decided to go with an XML parser which itself is able only to parse a valid XML, but not HTML. And to accomplish my goals I agreed to process HTML content with <a href="http://tidy.sourceforge.net/">html tidy</a> first (there is a <a href="https://metacpan.org/module/HTML::Tidy">HTML::Tidy</a>, an interface to htmltidy library).</p>

<p>So I’ve wrote a simple XS wrapper around pugixml and passed input through HTML::Tidy before parsing.</p>

<p>I’ve got 0.03765s per file, 11 hours in total. Which were 4.5 times faster than what I had before. And 25 times faster than initial <a href="https://metacpan.org/module/HTML::TreeBuilder">HTML::TreeBuilder</a>-based implementation.</p>

<p>And please, take into account that I was too lazy to strip off some additional queries I’ve put into that XS before benchmarking. That things made parsing more complex (and time consuming). Synthetic benchmarks show that PugiXML+HTML::Tidy tandem is ten(!) times faster than LibXML.</p>

<p>Later, in a two days or so, I’ve decided that, even disregarding simplicity of writing an XS wrapper, I would like to have such thing in a Perl land. And, in the long run, to get a drop-in replacement for Web::Scraper to use PugiXML.</p>

<p>Please, don't get me wrong. I'm not trying to say that HTML::TreeBuilder or XML::LibXML are bad. Thery do their job and do it perfect. But at the moment when somebody in the Perl land needs something that is as fast as possible... I just want it to be there, on CPAN.</p>

<p>And there are some cons behind these pros for writing/using this thing. Here are some of them:</p>

<p>pugixml is <a href="http://pugixml.googlecode.com/svn/tags/latest/docs/manual/loading.html#manual.loading.w3c">not fully W3C conformant</a>, as well as it’s <a href="http://pugixml.googlecode.com/svn/tags/latest/docs/manual/xpath.html#manual.xpath.w3c">XPath 1.0 implementation</a>.</p>

<p>And don’t be fooled by synthetic benchmarks I made. Final implementation might not be that fast. Say, “only” 5-6 times faster than LibXML.</p>

<p>However, from my point of view, implementation worth efforts.<br />
For example, if perlish PugiXML  was used  for processing RSS feeds, I believe that TheOldReader would not suffer <a href="https://twitter.com/TheOldReader/status/313423511332990976">that much from a hit by a 100 000 new subscribers</a> in a single day when Google announced shutdown of the Reader. And I think most of you have a use case for such speedy HTML/XML parser off the top of your head.</p>

<p>So I’ve drafted a <a id='plan' href="https://docs.google.com/document/d/13Q1xaGPyi8_LADH4A_BK6KxQt9frkedYgMLMFWyjr3A/edit?usp=sharing">rough plan</a> on implementation of Perl interface to pugixml and discussed it with the author of the original library, Arseny Kapoulkine. Feedback I received was encouraging.</p>

<p>And now...</p>

<p>I’m looking for your feedback. Would you use such thing if it is on CPAN?</p>

<p>I’m looking for your advices. Did I miss something? Do you have any additional concerns?</p>

<p>Finally, I’m looking for participants. If you would like to join development, I’d be happy to talk to you. Mostly because I like to meet new people, least because I’m lazy and would like to share that burden. And also, and it’s important, because I would like to have a co-maintainer(s) in order to make sure what we’ve done is supported for a while.</p>

<p>So don’t hesitate to write a comment or drop an email to <a href="mailto:yko@cpan.org">yko@cpan.org</a></p>

<p>Thanks</p>]]>
    </content>
</entry>

<entry>
    <title>Kiev.pm organizational changes</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/yko/2011/08/kievpm-organizational-changes.html" />
    <id>tag:blogs.perl.org,2011:/users/yko//716.2094</id>

    <published>2011-08-15T15:14:06Z</published>
    <updated>2011-08-15T15:15:31Z</updated>

    <summary>Dear Perl community! I&apos;m proud to say that today Sergey Gulko officially announced me as a leader of Kiev.pm group. Thank you Sergey and my appreciation to all members of Kiev.pm for approving me for this assignment and great support...</summary>
    <author>
        <name>yko</name>
        <uri>http://korshak.name</uri>
    </author>
    
    <category term="kievpm" label="kiev.pm" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/yko/">
        <![CDATA[<p>Dear Perl community!</p>

<p>I'm proud to say that today Sergey Gulko officially announced me as a leader of <a href='http://kiev.pm.org'>Kiev.pm</a> group. Thank you Sergey and my appreciation to all members of Kiev.pm for approving me for this assignment and great support during debates and planning stage. Guys, you are great! Sergey I wish you a very good luck in all spheres of your personal and professional life.</p>

<p>Kiev.pm community exists since June 1, 2007 and until today was lead by Sergey Gulko. Our community is about 200 registered members. During past few years we had organized two Perl workshops called ‘<a href='http://event.perlukraine.org/upw2009/'>Perl Mova</a>’ together with <a href='http://moscow.pm.org'>Moscow.pm</a>. This gave us an opportunity to meet Jonathan Worthington, Andrew Shitov, Alex Kapranoff and many other great people, collaborate and better know each other inside of the community.</p>

<p>I am happy that being a Perl monger brought me to know such seasoned professionals as Oleg Alistratov, Denis Zhdanov and Viacheslav Tykhanovskyi. I am learning a lot from them and I hope to learn more in future. I am absolutely sure that Kiev.pm can be proud of its young and talented members as Sergey Zasenko, Maxim Vuets, their energy, enthusiasm and expectations is the best engine for our community.<br />
And I’m sure this is only the beginning of Kiev.pm growth.</p>

<p>I want to help Perl people collaborate, meet each other and spread their knowledge within local and whole world Perl community as well as to keep Kiev.pm healthy and prosperous. I consider such activity to be my main task in capacity of pm group leader. I believe that combination of my communication and organizational skills and of course support of Kiev Perl Mongers community will help us to reach all seated goals.</p>

<p>If you want to get in touch with Kiev.pm representative about local events, meetings or any other issues feel free to contact me via email <a href='mailto:yko@cpan.org'>yko@cpan.org</a>.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Hello World in Plack 2: InteractiveDebugger</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/yko/2011/07/hello-world-in-plack-2-interactive-debugger.html" />
    <id>tag:blogs.perl.org,2011:/users/yko//716.1964</id>

    <published>2011-07-15T18:21:30Z</published>
    <updated>2011-07-15T16:22:59Z</updated>

    <summary>Another tool to debug your Plack application is InteractiveDebugger You can dive into your code, explore your stack and see all variables in each frame. And execute arbitrary code at some level! Just try it: plackup idebug-demo.psgi firefox http://127.0.0.1:5000/...</summary>
    <author>
        <name>yko</name>
        <uri>http://korshak.name</uri>
    </author>
    
        <category term="plack" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="plack" label="plack" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/yko/">
        <![CDATA[<p>Another tool to debug your Plack application is <a href='http://search.cpan.org/~miyagawa/Plack-Middleware-InteractiveDebugger/'>InteractiveDebugger</a><br />
<a href="http://blogs.perl.org/users/yko/img/Screenshot-Died%20at%20debug-demo.psgi%20line%2016%20--%20Plack%20Interactive%20Debugger%20-%20Chromium-1.png"><img alt="Screenshot-Died at debug-demo.psgi line 16 -- Plack Interactive Debugger - Chromium-1.png" src="http://blogs.perl.org/users/yko/assets_c/2011/07/Screenshot-Died at debug-demo.psgi line 16 -- Plack Interactive Debugger - Chromium-1-thumb-580x383-548.png" width="580" height="383" class="mt-image-none" style="" /></a><br />
You can dive into your code, explore your stack and see all variables in each frame.<br />
And execute arbitrary code at some level!</p>

<p>Just <a href='https://gist.github.com/1077734'>try it</a>:<br />
plackup idebug-demo.psgi<br />
firefox http://127.0.0.1:5000/</p>]]>
        <![CDATA[<p>D command shows all variables in frame and you can just dump any variable using Data::Dumper: <br />
<code>perl&gt; Data::Dumper::Dumper $self;</code><br />
It would be great to have perl debugger-like alias 'x' for this command, maybe it will appear in future.</p>

<p><script src="https://gist.github.com/1077734.js"> </script></p>]]>
    </content>
</entry>

<entry>
    <title>Hello World in Plack</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/yko/2011/07/hello-world-in-plack.html" />
    <id>tag:blogs.perl.org,2011:/users/yko//716.1963</id>

    <published>2011-07-12T08:59:03Z</published>
    <updated>2011-07-12T11:01:24Z</updated>

    <summary>I&apos;m was playing with PSGI spec and Plack last few days and found Debug middleware just amazing: You should just try it: plackup debug-demo.psgi firefox http://127.0.0.1:5000...</summary>
    <author>
        <name>yko</name>
        <uri>http://korshak.name</uri>
    </author>
    
        <category term="plack" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="plack" label="plack" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/yko/">
        <![CDATA[<p>I'm was playing with PSGI spec and Plack last few days and found <a href='http://search.cpan.org/~miyagawa/Plack-Middleware-Debug/'>Debug middleware</a> just amazing:<br />
<a href="http://blogs.perl.org/users/yko/img/Screenshot-Few%20words%20about%20Plack%20and%20PSGI%20-%20Chromium-1.png"><img alt="Screenshot-Few words about Plack and PSGI - Chromium-1.png" src="http://blogs.perl.org/users/yko/assets_c/2011/07/Screenshot-Few words about Plack and PSGI - Chromium-1-thumb-580x416-550.png" width="580" height="416" class="mt-image-none" style="" /></a><br />
You should just <a href='https://gist.github.com/1077653'>try it</a>:</p>

<p><code>plackup debug-demo.psgi<br />
firefox http://127.0.0.1:5000</code></p>]]>
        <![CDATA[<p>You can see all environment variables, generation time and memory usage before and after response. Find your memory leaks before they find you.<br />
<script src="https://gist.github.com/1077653.js?file=debug-demo.psgi"></script></p>]]>
    </content>
</entry>

</feed>
