How much slower can I reasonably expect perform: to be than a literal message send, on average? Should I avoid sending perform: in a loop, similar to the admonishment given to Perl/Python programmers to avoid calling eval("...") (Compiler evaluate: in Smalltalk) in a loop?
I’m concerned mainly with Squeak, but interested in other Smalltalks as well. Also, is the overhead greater with the perform:with: variants? Thank you
#perform:is not likeeval(). The problem witheval()(performance-wise, anyway) is that it has to compile the code you’re sending it at runtime, which is a very slow operation. Smalltalk’s#perform:, on the other hand, is equivalent to Ruby’ssend()or Objective-C’sperformSelector:(in fact, both of these languages were strongly inspired by Smalltalk). Languages like these already look up methods based on their name —#perform:just lets you specify the name at runtime rather than write-time. It doesn’t have to parse any syntax or compile anything likeeval().It will be a little slower (the cost of one extra method call at least), but it isn’t like
eval(). Also, the variants with more arguments shouldn’t show any difference in speed vs. just plainperform:whatever. I can’t talk with that much experience about Squeak specifically, but this is how it generally works.