Book Image

Delphi High Performance - Second Edition

By : Primož Gabrijelčič
5 (1)
Book Image

Delphi High Performance - Second Edition

5 (1)
By: Primož Gabrijelčič

Overview of this book

Performance matters! Users hate to use programs that are not responsive to interactions or run too slow to be useful. While becoming a programmer is simple enough, you require dedication and hard work to achieve an advanced level of programming proficiency where you know how to write fast code. This book begins by helping you explore algorithms and algorithmic complexity and continues by describing tools that can help you find slow parts of your code. Subsequent chapters will provide you with practical ideas about optimizing code by doing less work or doing it in a smarter way. The book also teaches you how to use optimized data structures from the Spring4D library, along with exploring data structures that are not part of the standard Delphi runtime library. The second part of the book talks about parallel programming. You’ll learn about the problems that only occur in multithreaded code and explore various approaches to fixing them effectively. The concluding chapters provide instructions on writing parallel code in different ways – by using basic threading support or focusing on advanced concepts such as tasks and parallel patterns. By the end of this book, you’ll have learned to look at your programs from a totally different perspective and will be equipped to effortlessly make your code faster than it is now.
Table of Contents (15 chapters)

Preface

Performance matters!

I started programming on 8-bit micros, and boy, was that an interesting time! Memory was typically not a problem, as we didn’t write big programs, but they certainly weren’t running fast, especially if you run them with a built-in BASIC interpreter. It is not surprising that I quickly learned assembler and spent lots of early years shifting bits and registers around. So did almost everybody else who wanted to release a commercial application written for one of those computers. There were, more or less, no games and applications written in BASIC simply because they would run too slowly and nobody would use them.

Times have changed; computers are now fast — incredibly fast! If you don’t believe me, check the code examples for this book. A lot of times, I had to write loops that spin over many million iterations so that the result of changing the code would be noticed at all. The raw speed of processors has also changed the software development world. Low-level languages such as assembler and C mostly gave way to more abstract approaches — C#, C++, Delphi, F#, Java, Python, Ruby, JavaScript, Go, and so on. The choice is yours. Almost anything you write in these languages runs fast or at least fast enough.

Computers are so fast that we sometimes forget the basic rule — performance matters.

Customers like programs that operate so fast that they don’t have to think about it. If they have to wait 10 seconds for a form to appear after clicking on a button, they won’t be very happy. They’ll probably still use the software, though, provided that it works for them and doesn’t crash. On the other hand, if you write a data processing application that takes 26 hours to do a job that needs to execute daily, you’ll certainly lose them.

I’m not saying that you should switch to assembler. Low-level languages are fast, but coding in them is too slow for modern times, and the probability of introducing bugs is just too high. High-level languages are just fine, but you have to know how to use them. You have to know what is fast and what is not, and ideally, you should take this into account when designing code.

This book will walk you through the different approaches that will help you write better code. Writing fast code is not the same as optimizing a few lines of your program to the max. Most of the time, that is, in fact, the completely wrong approach! However, I’m getting ahead of myself. Let the book speak for itself.