Live data from Hacker News

Ask HN: Largest speedup you ever achieved by only changing a few lines of code?

news.ycombinator.com

1–10 of 26 posts

Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?

#3
Dropped a request by 40 seconds, by preventing entity framework round-tripping the db 3000+ times, for a property which was already held in memory! Pretty much a 1 liner change. Took some time to find, and the use of miniprofiler (thx Stackoverflow!).

Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?

#5
post #2

Modified an SQL query... went from a few minutes, to a few seconds.

I had one like this with a stored procedures. I don’t recall what the exact issues was, but one of the solutions involved declaring a few variables and then copying the procedure parameters into those instead of passing them directly into a query.

Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?

#6
Some basic word counting on text files in bash, I was tokenizing to one token per line and then counting:

tr -cs '[:alnum:]' '[\n*]' | sort | uniq -c

The sort takes a long time (probably just n log n I guess) on a big text. Swapping for

awk '{k[$0]++} END {for (token in k) print token, k[token];}'

and then sorting on the numbers does the same thing faster.

Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?

#7
Just last week, dropped latency of a serial logger interface of an MCU by several milliseconds, by using DMA instead of traditional interrupt/polling mechanism. That also had an added benefit of making the log queue almost always empty, consequently never missing a logging entry.

Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?

#8
Started a new job working on a company's API team. The API had out of memory issues and had processes crashing all the time.

The code was PHP. All API calls ended like this:

echo json_encode($data) . "\n";

Changed just one character, the period to a comma so the string wasn't duplicated before being output. Problem solved. Felt like a hero.

Post reply on HN