Ask HN: Largest speedup you ever achieved by only changing a few lines of code?
1–10 of 26 posts
No post body was provided.
Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?
#2Modified an SQL query... went from a few minutes, to a few seconds.
Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?
#3Dropped 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?
#4Iterating via reference instead of copy in C++ is a great way to get a speed up with a one character change.
I.e. changing for (const MyType v : collection) to for (const MyType& v : collection)
Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?
#5Modified 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?
#6Some 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?
#7Just 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?
#8Started 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.
Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?
#9MongoDb driver in C# was failing to convert LINQ expression to mongo query. I noticed it added unit test to make sure it would never silently do in-memory filter. Night and day difference.
Re: Ask HN: Largest speedup you ever achieved by only changing a few lines of code?
#10changed from single thread to multi-threads,
changed std::map to std::unordered_map