Why are you interested in Pony? We bet at least a bit of your answer involves its promise of high-performance code. When it comes to writing code that runs fast, Pony sets you up for success in a way that few languages do. That said, you can still write slow code.
The patterns in this chapter aim to help teach you a variety of tricks to help you write fast code. Most of them will focus on one or both of the following:
- Limit memory allocations
- Limit the number of objects your create
Neither of these techniques is unique to Pony. They are both fairly standard means of getting more performance from programs in any language. How you go about that is often specific to individual languages. Here’s your entree getting the most out of Pony.
Problem Your code is performance sensitive and needs to make your String concatenation code as fast as possible.
Solution Replace any usage of String.add with String.append. Going from code like:
let output = file_name + ":" + file_linenum + ":" + file_linepos + ": " + msg to String.append where we pre-allocate the memory needed to hold our final string.
let output = recover String(file_name.size() + file_linenum.size() + file_linepos.