Book Image

Clojure High Performance Programming

By : Shantanu Kumar
Book Image

Clojure High Performance Programming

By: Shantanu Kumar

Overview of this book

<p>Clojure is a young, dynamic, functional programming language that runs on the Java Virtual Machine. It is built with performance, pragmatism, and simplicity in mind. Like most general purpose languages, Clojure’s features have different performance characteristics that one should know in order to write high performance code.<br /><br />Clojure High Performance Programming is a practical, to-the-point guide that shows you how to evaluate the performance implications of different Clojure abstractions, learn about their underpinnings, and apply the right approach for optimum performance in real-world programs.<br /><br />This book discusses the Clojure language in the light of performance factors that you can exploit in your own code.</p> <p>You will also learn about hardware and JVM internals that also impact Clojure’s performance. Key features include performance vocabulary, performance analysis, optimization techniques, and how to apply these to your programs. You will also find detailed information on Clojure's concurrency, state-management, and parallelization primitives.</p> <p>This book is your key to writing high performance Clojure code using the right abstraction, in the right place, using the right technique.</p>
Table of Contents (15 chapters)
Clojure High Performance Programming
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Clojure is a remarkably high-performance language despite its dynamic nature. What really strikes you though is the fact that it combines performance with fundamental simplicity and pragmatism, which makes it such a joy to program in. Over the last six years since its first public release, Clojure has been heavily tested and deployed in production by many people and organizations across various domains. Its user base has grown rapidly during this period.

Clojure High Performance Programming is all about Clojure running on the Java Virtual Machine. The JVM has a reputation of being a robust platform to develop and deploy applications on. In this book, we take a deeper look at the performance characteristics of various features of Clojure and the underlying environment. We also explore what it takes to build well-performing software. We begin with the performance fundamentals and gradually proceed over to Clojure and other matters you may have to deal with while writing high-performance applications.

Understanding and achieving performance is both an art and a science, just like writing good software. Remember the big picture in the back of your mind but also be prepared to get into the details with measurement tools. More importantly, know how the software works and keenly study the environment in which it runs. I hope this book will help you on that path.

What this book covers

Chapter 1, Performance by Design, classifies the various use cases with respect to performance and analyzes how to interpret their performance aspects and needs.

Chapter 2, Clojure Abstractions, is a guided tour of various Clojure data structures, abstractions (persistent data structures, vars, macros, and so on), and their performance characteristics.

Chapter 3, Leaning on Java, discusses how to enhance performance by using Java interoperability and features from Clojure.

Chapter 4, Host Performance, discusses how the host stack impacts performance. Clojure being a hosted language, its performance is directly related to the host.

Chapter 5, Concurrency, is an advanced chapter that discusses concurrency and parallelism features in Clojure and the JVM. Concurrency is an increasingly significant way to derive performance.

Chapter 6, Optimizing Performance, discusses the systematic steps that need to be taken in order to obtain good performance.

Chapter 7, Application Performance, discusses building applications. This involves dealing with external subsystems and factors that impact the overall performance.

What you need for this book

You should acquire Java Development Kit Version 7 or higher for your operating system to work through all examples. This book discusses the Oracle HotSpot JVM in specific situations, so you may want to get Oracle JDK or OpenJDK if possible. You should also get the latest Leiningen version (Version 2.3.3 as of the time of writing) from http://leiningen.org/ and JD-GUI from http://jd.benow.ca/.

Who this book is for

This book is for intermediate Clojure programmers who are interested to learn how to write high-performance code. If you are an absolute beginner in Clojure, you should learn the basics of the language first and then come back later to this book. You need not be well-versed in performance engineering or Java. However, some prior knowledge of Java would make it much easier to understand the Java-related chapters.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "If you want Criterium to be available only in the REPL and not as a project dependency, add the following entry to the ~/.lein/profiles.clj file."

A block of code is set as follows:

(import 'java.util.concurrent.Callable)
(import 'java.util.concurrent.Future)
(def ^ExecutorService e (Executors/newSingleThreadExecutor))
(def ^Future f (.submit e (cast Callable #(reduce + (range 10000000)))))
(.get f)  ; blocks until result is processed, then returns it

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Clicking on the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.