From c18994f49cb56825009361298c0a9345583ba1b9 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 15 Jul 2019 19:59:20 -0300 Subject: [PATCH] New chapter: optimization --- content/books/things-i-learnt/_index.md | 1 + .../things-i-learnt/config-file/index.md | 2 +- .../things-i-learnt/optimization/index.md | 39 +++++++++++++++++++ .../books/things-i-learnt/use-utf8/index.md | 2 +- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 content/books/things-i-learnt/optimization/index.md diff --git a/content/books/things-i-learnt/_index.md b/content/books/things-i-learnt/_index.md index 6013d97..1b2c827 100644 --- a/content/books/things-i-learnt/_index.md +++ b/content/books/things-i-learnt/_index.md @@ -50,6 +50,7 @@ template = "section-contentless.html" * [Start Stupid](start-stupid) * [Always Use Timezones With Your Dates](use-timezones) * [Always Use UTF-8 For Your Strings](use-utf8) + * [Optimization Is For Compilers](optimization) * Making Things Go * [The Config File Is Friend](config-file) * [Command Line Options Are Weird, But Helpful](command-line-options) diff --git a/content/books/things-i-learnt/config-file/index.md b/content/books/things-i-learnt/config-file/index.md index d1393df..692736a 100644 --- a/content/books/things-i-learnt/config-file/index.md +++ b/content/books/things-i-learnt/config-file/index.md @@ -52,4 +52,4 @@ you'll find that you're half-way through it. [^1]: In other words, they have a [time to live](https://en.wikipedia.org/wiki/Time_to_live). -{{ chapters(prev_chapter_link="/books/things-i-learnt/use-utf8", prev_chapter_title="Always Use UTF-8 For Your Strings", next_chapter_link="/books/things-i-learnt/command-line-options", next_chapter_title="Command Line Options Are Weird, But Helpful") }} +{{ chapters(prev_chapter_link="/books/things-i-learnt/optimization", prev_chapter_title="Optimization Is For Compilers", next_chapter_link="/books/things-i-learnt/command-line-options", next_chapter_title="Command Line Options Are Weird, But Helpful") }} diff --git a/content/books/things-i-learnt/optimization/index.md b/content/books/things-i-learnt/optimization/index.md new file mode 100644 index 0000000..333e36a --- /dev/null +++ b/content/books/things-i-learnt/optimization/index.md @@ -0,0 +1,39 @@ ++++ +title = "Things I Learnt The Hard Way - Optimization Is For Compilers" +date = 2019-07-15 + +[taxonomies] +tags = ["en-au", "books", "things i learnt", "optimization"] ++++ + +Let say you need more performance on your application. You may be tempted to +look at your code and think "How can I keep this same logic and still remove a +few cycles, so things seem to go faster?" Well, if you want performance, you +need to change your logic. + + + +But before jumping into the code, you may have to check your compiler options. +Maybe you're not generating the optimized version. Maybe there is an option +that you don't use that you can remove from the compilation. + +'Cause "optimization" is what a compiler is for. They _know_ where they can +extract most of the underlying architecture, and people have been finding ways +to make the compiled code more performance for decades. Heck, compilers can +even _delete_ parts of your code 'cause they can "see" that a piece of code +will always produce the same result and, thus, isn't necessary and they will +just put the same result where that piece of code was. + +What you need to do is to think about a better _design_ for your code, not how +to improve the current code. And trying to trick the compiler by [messing with +the types](/books/things-i-learnt/data-types), although may produce faster +code, will really screw you in the future -- specially cause maintenance and +code understanding will take long and figuring out what went wrong will always +be harder. + +Code is written for humans to read. _ALWAYS_. Optimization is what compilers +do. So find a smarter way to explain what you're trying to do instead of using +shorter words or messing with that your code is saying. + +{{ chapters(prev_chapter_link="/books/things-i-learnt/use-utf8", prev_chapter_title="Always Use UTF-8 For Your Strings", next_chapter_link="/books/things-i-learnt/config-file", next_chapter_title="The Config File Is Friend") }} + diff --git a/content/books/things-i-learnt/use-utf8/index.md b/content/books/things-i-learnt/use-utf8/index.md index 3d24960..3c7e33d 100644 --- a/content/books/things-i-learnt/use-utf8/index.md +++ b/content/books/things-i-learnt/use-utf8/index.md @@ -52,4 +52,4 @@ single character. Walking through the whole string would require traversing the string character by character, instead of simply jumping straight to the proper position. But that's a price worth paying, in the long run. -{{ chapters(prev_chapter_link="/books/things-i-learnt/use-timezones", prev_chapter_title="Always Use Timezones With Your Dates", next_chapter_link="/books/things-i-learnt/config-file", next_chapter_title="The Config File Is Friend") }} +{{ chapters(prev_chapter_link="/books/things-i-learnt/use-timezones", prev_chapter_title="Always Use Timezones With Your Dates", next_chapter_link="/books/things-i-learnt/optimization", next_chapter_title="Optimization Is For Compilers") }}