Live data from Hacker News

Ask HN: What is your go to performance optimization?

news.ycombinator.com

1–10 of 47 posts

Re: Ask HN: What is your go to performance optimization?

#4
umm this is kinda tongue-in-cheek

```

#include

#include

int main(int argc, char argv[]) { int i = 0; time_t timep;

        /*
         * ok so now we are printing something
        **/
        printf("Greetings!\n");

        /*
         * this is a for loop from 0..9
        **/
        for(i=0; i
}

```

now, the canonical

```

$> gcc tz-test.c -o obj/tz-test

```

now do this

```

$> unset TZ

$> strace -ff ./obj/tz-test 2>&1 | grep 'local' | wc

     10      77     851
$> export TZ=:/etc/localtime

$> strace -ff ./obj/tz-test 2>&1 | grep 'local' | wc

      1       5      59

```

moral, always set TZ to avoid localtime(3) from stat'ing /etc/localtime :o)

Re: Ask HN: What is your go to performance optimization?

#5
I've spent the last couple of years identifying and resolving N+1 problems in a Django codebase.

https://planetscale.com/blog/what-is-n-1-query-problem-and-h...

Aside from the performance gains, it's very satisfying to go from 1,000+ inefficient DB queries to 1-2 optimized queries.

Re: Ask HN: What is your go to performance optimization?

#9
Reduce how often something runs and the amount of work it does when it does run. Sometimes, things are done too often, or process unnecessary data.

I once had a project where a SAP system was crawling and literally causing company-wide stoppages. We found a job that literally ran every minute of every day and it processed a table that contained a few thousand tasks. This was something that could be done once per hour, and only during business hours. Furthermore, it was re-processing thousands of records each time it ran. In reality, after a record was processed once, it could be deleted from the table.

We emptied out the table, and scheduled the job to run hourly. The whole company noticed an immediate improvement.

This pattern happens a lot. Someone builds a polling system that hits the server once a second in order to see if a task finished. A cron job runs every 5 minutes. All data is processed in a daily job, instead of doing a 24 hour cutoff.

The world is filled with computers doing useless work. Mostly, no one notices.

Post reply on HN