I don't know anything about your exact requirements and what your scripts do. But i have a feeling you are doing a lot of data munching. I assume you tried putting your data in a database like PostgreSQL and implementing the time critical parts in SQL?

Example: For a year now i had some performance problems on my DNS server written in Perl. It had to do with white/blacklisting of domains. Basically, it had to do about a million string matches for every request, plus a few thousand regexp matches. I moved the whole matching algorithm into PostgreSQL. It isn't all that optimized yet, but it runs in a fraction of the time:

CREATE OR REPLACE FUNCTION pagecamel.nameserver_isforcenx(search_domai +n_name text) RETURNS boolean LANGUAGE plpgsql AS $function$ DECLARE tempvar boolean := false; BEGIN -- Check whitelist (non-regex) SELECT INTO tempvar EXISTS(SELECT 1 FROM pagecamel.nameserver_forc +enxdomain_whitelist WHERE is_regex = false AND search_domain_name = doma +in_match); IF tempvar = true THEN -- whitelisted RETURN FALSE; END IF; -- Check whitelist (regex) SELECT INTO tempvar EXISTS(SELECT 1 FROM pagecamel.nameserver_forc +enxdomain_whitelist WHERE is_regex = true AND search_domain_name ~* doma +in_match); IF tempvar = true THEN -- whitelisted RETURN FALSE; END IF; -- Check blacklist (non-regex) SELECT INTO tempvar EXISTS(SELECT 1 FROM pagecamel.nameserver_forc +enxdomain WHERE is_regex = false AND search_domain_name = doma +in_match); IF tempvar = true THEN -- blacklisted RETURN TRUE; END IF; -- Check blacklist (regex) SELECT INTO tempvar EXISTS(SELECT 1 FROM pagecamel.nameserver_forc +enxdomain WHERE is_regex = true AND search_domain_name ~* doma +in_match); IF tempvar = true THEN -- blacklisted RETURN TRUE; END IF; -- Neither, so NOT blacklisted RETURN false; END; $function$;

Perl is quite good in general. But when it comes to handling large amounts of data, no "normal" scripting language comes even close to a modern SQL database engine like PostgreSQL. People on those projects spent the last few decades optimizing every last tenth of a percent of performance.

Yeah, there is probably a way to optimize that function using the WITH() clause and/or having some special type of INDEX on the table that's somehow optimized to handle regular expressions or something.

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

In reply to Re: Trading compile time for faster runtime? by cavac
in thread Trading compile time for faster runtime? by melez

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.