Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


Don't take what I'm about to write as disagreeing with you. It is more about the thought process that went into my choice to use CGI::Ajax for the example. Your points are strong, although possibly not complete: You've validly pointed out that clarity and 'non-intrusiveness' suffers in my example. What you missed is that it traded it for performance.

I deliberately used CGI::Ajax to reduce the amount of explict Javascript I used for the example. You see, I normally just add the actual Javascript generated by CGI::Ajax as another block of output text - without actually using the CGI::Ajax module. I used the actual CGI::Ajax module here to make a clearer example without the burden of a full fledged toolkit like JQuery.

Sound backwards?

Not really. You see, performance and size tend to be my primary goals because I frequently need these kinds of scripts to be used on web pages that both receive many hits per day and that are already overly heavy byte-wise.

So my goals of "runs fast, loads fast" compromised with the goals of "code clarity, full featured" to settle on CGI::Ajax for the example to get "Ajax clarity, acceptable performance".

Code clarity would have argued for using one of the major JS toolkits. Performance would have argued for eliminating CGI::Ajax entirely and not using a toolkit library.

As a data point to illustrate my point on performance, I modified my script to follow my normal practice of inlining the Ajax support Javascript as part of my Perl and benchmarked it for 1000 requests at a concurrency of 20 using the 'ab' Apache benchmark script (with a dry run in each case to allow the server to 'get up to speed'). I also made the minimal modifications required to make run under FastCGI as another comparision point. The tests were run using Apache2 on a hyperthreaded 3Ghz P4 machine running Fedora Core 6 Linux (with a second machine making the HTTP requests).

CGI ModPerl2 FastCGI Original Example 24/sec 397/sec 328/sec Inlined Ajax JS 69/sec 505/sec 446/sec

Why such a dramatic slowdown when using CGI::Ajax? Because it pulls in a lot of extra Perl code to generate that chunk of Javascript. CGI::Ajax is about 41K, and it pulls in Exporter (14.4K), Data::Dumper (38K), base (5.4K), overload (46K), vars (2.3K), warnings::register (1K), and Carp (8.8K). For a startling 156K of Perl to generate just under 7K of final Javascript using CGI::Ajax. While the ModPerl2 and FastCGI environments are not nearly as sensitive to the byte count, there is still a noticable runtime overhead to the dynamic code generation of CGI::Ajax.

Similiar issues arise using the off-the-shelf Ajax libraries. They add dozens to hundreds of Kbytes of stuff needing to be loaded by the web browser (with dramatic performance consequences resulting just from that fact). Additionally, they tend to run slowly above and beyond that (Digg is a classic example - they use an off-the-shelf JS Ajax library that causes my machine to bog completely down on their longer pages. It is quite annoying.)

So, in addition to your (excellent) suggestion of covering the use of off-the-shelf Ajax JS libraries, I need to cover when-and-why NOT to use them.

In reply to Re^2: AJAX popup windows - an example by snowhare
in thread AJAX popup windows - an example by snowhare

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2021-09-20 20:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found