Paul Battisson is the Chief Operating Officer for Cloud Galacticos. In this episode, we are talking about the convergence of two of his favorite things: “super hardcore nerdy math” (as Paul puts it) and Apex.

Paul has performed some unique experiments that combined his love for math with his love for Apex. In our conversation, we talk about those experiments at length. We go into some detail about what factors can affect Apex performance and weirdly, talk a lot about pigeons.

Show Highlights

  • Paul’s inspiration for learning how to code.
  • What Machine Learning is and how it is architected
  • Why Paul wanted to get Machine Learning (ML) in Apex.
  • The difference between Machine Learning and Artificial Intelligence (AI).
  • Where matrices fall into the toolset of creating Machine Learning.
  • How linear regressions are utilized in Machine Learning.
  • All about Paul’s Virtual Reality (VR) experiment in Apex.
  • The pitfalls of enterprise VR and where Paul sees it going in the future.
  • Specifics on how to increase performance in iterators
  • What heap size is and how it affects performance
  • What Paul’s two books are about.

Links

Episode Transcript

Paul Battisson:
This will shock you, but for a guy who’s really into deep math, I was a slightly insular nerdy child who enjoyed playing … There’s a game in Britain called Championship Manager. I loved playing that. All the teenagers were like, “I want to write my own video game.”

Josh:
That is Paul Battisson, chief operating officer for Cloud Galacticos. I’m Josh [Berk 00:00:28], your host for the Salesforce Developer Podcast, and here on the podcast, you’ll hear stories and insights from developers for developers. Today we sit down and talk with Paul about some of the weird experiments he’s done with two things. One, his love for, and I’m quoting him here: “super hardcore nerdy math” and APEX, as well as some other parts of the platform. Also at some point, we start talking a lot about pigeons. But to kick things off, we go back to that [inaudible 00:00:54] and talk about the program languages he was learning to make that game.

Paul Battisson:
Yes, going into computer programming, started off with things like Dark Basic and Blitz Basic and some of those variants, and then took a weird dark twist down into learning Perl and C. I can’t remember any Perl now, so please don’t ask me any, because it’s … Perl is the worst language to learn for a starter language. It’s awful. Everything’s string and nothing makes sense.

Josh:
Yes.

Paul Battisson:
So yes, that was it. So I went down that route, was doing it, the CTO at Cloud Galacticos where I am now actually was a guy I worked with when I was just prior to going to university. I was helping program the credit card systems at a major newspaper, I won’t share which one. Hopefully they’re not in use anymore. An 18-year-old doing that. And then yeah, I went away to university and loved maths, and kind of went and did that, and then when I graduated was just about the time that the financial crash was destroying the world. So all of my dreams of being an investment banker and being a millionaire on a yacht somewhere were dashed.

Paul Battisson:
I actually had an interview for an investment banking job the day Neiman Brothers collapsed, and the guy interviewing me was like, “There’s no job here, man. I’ll give you some free interview practice, but there’s no job.”

Josh:
Wow. That’s … Wow. Okay, so, a few things. I find it fascinating that you have this rarity of a connection in math, however you also just said two things which have come up before. “Oh, I wanted to play … Make my own video games, so I’m going to go learn how to code,” and, I don’t know what the right term is, but we’re Perl brothers. That was the first language I actually started actually coding web applications in, and I agree with you. Not the best way to go.

Paul Battisson:
I had a really thick book, which was Perl Web Applications with CGI in Easy Steps. I swear, it was something like that. But this book was four inches thick, and I just remember being 14, 15, and my dad saying to me, “What are you reading? And if that’s easy steps, surely you need to go do something else.”

Josh:
Cool. So I am personally terrible at math, and I do think it’s kind of funny, because the whole conflation thing. People are like, “You’re good at programming, you must be good at math.” And I’m like, “No, I’m always around a supercomputer that’s good at math, and I just ask that questions. Like what’s that?” So for a non-math person like me, can you explain what the no-cloning theorem is?

Paul Battisson:
So, first of all, no one is bad at maths. Or math. So, everyone’s really good at it, because I will bet you a beer next time we see each other, Josh, that if you go into a shop and you’re given the wrong change, you can say that pretty quick. Or if you were outside, I don’t know if you’ve got kids, but if you and I were outside just throwing a football to each other, you can figure out how to catch that football.

Josh:
Sure.

Paul Battisson:
And that’s like doing advanced equations in your head. It just so happens that you’re not sitting them down and writing out the numbers. So no one is inherently bad at it. I think people don’t like it because it’s abstract and badly explained.

Josh:
Okay. Okay.

Paul Battisson:
So I have this thing where like, everyone’s good at this. Everyone is good at everything, in my mind. You just need the right kind of context for it. So, the no-cloning theorem, that was what my master’s thesis was on, and I’m wondering where you dug that up from.

Josh:
It might just so happen to be on your LinkedIn.

Paul Battisson:
Oh, there we go, okay. You were LinkedIn scouting. So, the basic idea is there’s this weird thing that quantum particles do called entanglement. So if you entangle these two photons or whatever, and take them as far apart as you want, they can transfer information. The idea is that they cannot transfer information. So if you change one, the other changes instantaneously, but the argument there is could you communicate faster than light, and blah blah blah. Which Einstein did not like, and so the no-cloning theorem kind of uses the same principle of entanglement to help show that you can’t ever make a perfect copy of a state.

Paul Battisson:
If you try and copy something, you effectively destroy it. You can get close, I think at the time when I did that it was 80-something percent good, but there’s no quantum Xerox machine.

Josh:
Got it. This may be a first, I might have to put a Wikipedia link to that in the show notes.

Paul Battisson:
Well, I hope now, for anyone who reads that Wikipedia link and then comes up to me and says, “You’ve explained that wrong,” it’s 30 seconds on a podcast. Come on.

Josh:
Fair, fair. Okay, so we’re here to talk about … And I’m using your words here, your weird experiments in APEX.

Paul Battisson:
Yes. I like to do odd things.

Josh:
Yes. Starting with getting machine learning within APEX. Now, with Einstein out there, is there a practical reason for doing that, or was this purely for the challenge?

Paul Battisson:
So, this pre-dates Einstein. I’m going to claim and hold to the fact that I was the first person to talk about machine learning with Salesforce. If Marc Benioff wants to take me out for a nice meal and discuss it, we can do so, but I am going to hold onto that fact. Yeah. I was looking into doing a machine learning course on Coursera. It’s the Andrew one that everyone has done. It’s really, really good, and yeah, just was doing that and happened to talk to a coworker at the time who said, “Yeah, but you couldn’t do that on Salesforce.” And was whinging about how bad Salesforce was. I was like, “Yeah, you could.” So, because someone said that I couldn’t, I went and did it. Myself and a former colleague of mine, [Jen Wire 00:06:58], who also has a background in maths. Two math programmers went and built a machine learning system in APEX that did what’s called [K means 00:07:08] clustering. So it’s grouping things together.

Josh:
Okay. So kind of like the no-cloning question, can you explain machine learning to me like I’m five?

Paul Battisson:
Yes. So, machine learning is basically … Oh, in fact, I’ve got a fantastic story about this the other day. So, they started pitching to some companies that have taught, or some group that have taught, pigeons to identify spots on brain scans or MRI’s for tumors. Yeah, so you’ll see where I’m going with this and how this goes back to machine learning in a minute. Because obviously, the valley is now going to be flush with pigeon-based startups. But the idea is that you just show a pigeon a bunch of pictures, and it gets a reward for tapping on the right spot on the screen. It doesn’t know what it’s doing, it just knows that if it taps the right spot, it gets a treat. That’s all machine learning is, is that you are showing a machine a bunch of pictures, and every time it gets it right, you’re saying, “Well done machine, now have another go and see if you can do better.” And it just does that.

Paul Battisson:
So there’s a load of very odd mathematics and matrix algebra and all these things behind it, but at the end of the day, if you can get the idea that you show a pigeon a bunch of images, and the pigeon gets a reward for tapping the right spot, that’s all your machine learning algorithm is doing, is it is just giving the machine lots and lots of data, telling it when it’s hitting the right spot, and giving it a reward, and the machine coming back and trying again and again and again.

Josh:
Gotcha. So I love that you used the pigeon example, because it segues brilliantly, I think, into this next question, because there’s machine learning, and then there’s old-school sci-fi AI. Hal 9000. And you’re not trying to make APEX sentient, right? Those are two very different things.

Paul Battisson:
Yeah, very, very different things. So machine learning is like a subset of AI. AI is a very catch-all generic term, like “analytics.” What does analytics mean? I’m sure there’s an [aide 00:09:09] that will somewhere tell me exactly what it means, but it’s a very generic term. So, artificial intelligence as a term is just having a computer perform a task like a human, without necessarily being told the exact instructions.

Josh:
Gotcha.

Paul Battisson:
Whereas machine learning is a specific implementation of AI, where it’s like, show it a million examples and let the machine try and guess. And that’s only … It was actually very popular back in the 80s, and earlier on than that, machine learning, but it kind of fell out of fashion because everyone realized that they had very low powered computers, and then suddenly we have this thing called the cloud now, where you can process hundreds of millions of things over and over again, so it becomes a lot easier. It’s also the volume of data, as well. It’s one of those things like with … I had a customer I was working with not that long ago who had 1.3 million contacts in their database.

Josh:
Oh, wow.

Paul Battisson:
And it’s that sort of thing that if you think when you first started working with IT systems, how many databases did you see of 1.3 million contacts? And this wasn’t a Fortune 500 company or a FTSE 100 company.

Josh:
Right.

Paul Battisson:
This was a charity. It’s crazy.

Josh:
Right. That’s actually interesting. I’m kind of slapping myself in the forehead, because I, having evangelized Einstein and all of this stuff, I saw the cloud as a convenient delivery system for machine learning, but within the intake and the output, right. Because it’s just your browser, at that point. But it honestly never occurred to me that the pure depth of the CPU potential, and also the depth of data, just mirrors up to what machine learning needs right away.

Paul Battisson:
Yeah. I’m going to get the statistic wrong, but I think it was a billion hours of YouTube are watched every day, or a billion videos, or something. There’s a number one billion, I’m pretty sure it’s hours, of YouTube are watched every day. And that’s why YouTube’s algorithm is so good at giving you the next video of whatever it is you want to see.

Josh:
Oh.

Paul Battisson:
It’s because they’ve got … Say they worked on a percent of that data. That’s 100 million videos for them to churn through every … Yeah.

Josh:
It’s a lot of pigeons.

Paul Battisson:
It’s a lot of pigeons.

Josh:
Okay, so you have three blog posts that I read up on this for this interview, and the first one discusses and goes into the math behind using matrices for machine learning. It’s a podcast, so we can’t really get too deep into the math, and I don’t know how much of it I was following anyway, to be honest, but tell me, why was this your first step? Where to matrices fall into the tool set of creating machine learning?

Paul Battisson:
Yeah, so I think I’ve just realized as well that when we’re talking about math, here, I’ve just said that 100 million is one percent of a billion, so let’s just … I think it’s also when people say you’re good at math, just to go back to an earlier point, they think good with numbers. I can’t add up. It’s a running joke in my family. If I’m at a restaurant with you, if you ask someone to split the bill, do not ask me to do it. I would rather pay the entire bill than be asked to split it. Numbers are not my thing. Squiggles on pages, I’m good with.

Josh:
Gotcha.

Paul Battisson:
Catching your own bad arithmetic. So yeah, we’re talking about matrices and machine learning. So the reason it comes together is that if you think that effectively what you’re trying to do is you’re trying to solve a big bunch of equations at once, you’re trying to say, “If I have these 10 inputs, and I want to give 10 outputs, and they’re all connected to each other, how do I multiply them together to get that right value?

Josh:
Okay.

Paul Battisson:
And that’s where matrices come in. So it’s a part of linear algebra for solving multiple … I don’t know if you’ve ever come across simultaneous equations. The standard high school one is you have five apples and four oranges, and it costs you $3.50, and your friend buys two apples and six oranges, and it costs them $2.90, how much is an apple? How much is an orange? And you obviously can write the equations down here and solve that. What you’re doing with matrices and with machine learning is doing that, but with, “I have apples and oranges and bananas and pears, every single fruit you can think of, and I also have their colors, and their weird other factors I’ve got going on, and I’ve got me and 50,000 of my closest friends to tell you how much it’s cost for us to get these things. Please work that out.”

Josh:
Yeah, gotcha. So it’s like a super-dimensional grid of all the things that you need to point pigeons at. Okay. So then, in the second post, you’re talking about linear progression, and I think I’m guessing where this is going, but mathematically, where does the linear progression then delve into the matrices?

Paul Battisson:
Yes, so linear regression. So if you think about, the standard thing is height and weight. Typically, someone who is 6’8″ is unlikely to weigh seven stone, or I don’t know what that is in pounds. They’re not going to weigh that much, whereas someone who is 4’5″ is not going to weigh 30 stone. So there’s a definitive correlation between height and weight. And if you plot all those points out on a scatter graph, and then just draw a line of best fit, that’s called linear regression, where you’re just trying to find the one line that goes through it in the best way. And that’s really easy when you’re thinking of two dimensions. You’re thinking of height and you’re thinking of weight.

Paul Battisson:
But what if I said to you, height, weight, and age? Now you could plot that again, as a best fit plane, so if you imagine almost a sheet bended out in different shapes to do it, and what you’ve got to find is where that fits best, and that’s real easy to do in two dimensions, because you can see it. In three dimensions, Excel could draw it. What if, again, we got to like 17 dimensions? I remember one morning walking into a lecture hall, and it was 9 am. Math students always get the worst lecture times. 9 am, I was a student so I’d been out the night before. Hadn’t got a lot of sleep, and then the lecturer was like, “Okay, let’s start off by imagining a five dimensional sphere.”

Paul Battisson:
At that point, I think it was …

Josh:
It was done.

Paul Battisson:
Yeah, the lecture was … I don’t remember anything else.

Josh:
Nice.

Paul Battisson:
I had a friend whose notes I used afterwards. And that’s it. Humans are very bad at visualizing all these different things.

Josh:
Right.

Paul Battisson:
So that’s where the matrices come in again, is helping pull out a framework for the computer to do that.

Josh:
For pushing things through. So if I’m following this right, the matrices are the boxes that we’re going to put the pigeons in front of, and then the linear regression is the means that you can determine if the pigeons are actually poking at the right dot.

Paul Battisson:
Yeah. That’d be a fair way to put it. So the matrices are really all of the images that the pigeons will look at, and then the linear regression is saying, “How good is our pigeon doing?” And then over time, our pigeon will get better and better at guessing. And what we’re trying to do is minimize the deviation. So if you were to imagine that simple height and weight chart again, you can think of the line of best fit, because you can intuitively see it. But if you were to tilt it one way or tilt it the other, the error you would have on average goes up, because you’re just drawing a silly line somewhere. So what we’re trying to do is minimize that line, and minimize that error.

Josh:
Got it.

Paul Battisson:
We’re showing all these pictures, our pigeons are guessing correctly, and yeah. We’re finding out how good the pigeon can get, and try to get the pigeon as best as we can.

Josh:
So, speaking of how good the pigeon can get, how successful were you with this experiment?

Paul Battisson:
So, we got it running. There was a Dreamforce presentation. All Dreamforce talks have to end with success. I’m pretty sure. I think at the time, it was back in 2014, so someone like [Reid 00:17:45] or yourself would have probably been betting them all in the background. At that point, if you just see, like, doesn’t work. Pull that one. So yeah, it worked. We took a bunch of data from the United Nations, ran it through, and we were able to reproduce a clustering of countries by different development factors. And it was interesting because we had some things that showed up the same as the UN’s own data, and some things that showed up that were like, “Huh. That’s interesting.”

Josh:
Nice. Nice, awesome. Let’s move on to another experiment of yours. I guess this is a little bit more front-end-y but there’s definitely some APEX involved. You also put together a virtual reality experiment. This is going back to the day, because I believe it was in Visualforce, but what lead you down that route in the first place? What got your interest in VR?

Paul Battisson:
So VR was, I don’t know, this was 2016? 2017?

Josh:
2016 I think it was, yeah.

Paul Battisson:
So, VR was just coming out then. The PlayStation VR wasn’t out. Oculus had a dev kit just out, at the time.

Josh:
That’s right, yeah.

Paul Battisson:
Those things were super expensive, and so I was like, there’s got to be a way of doing this. Because Google came out with the Google Cardboard. Super cool, but tech that cost $3. So I had one of those, had an iPhone, or Android phone, can’t remember at the time. It was working all good, and I was trying to … Another colleague of mine at the time, Vincent [Reader 00:19:20], and I said to him, “It would be really cool if you could do some VR stuff. I wonder if you could do it with Salesforce to visualize things.” And then he said to me, “Yes, we should build this. We should submit it for Dreamforce, and have you read Ready Player One?”

Paul Battisson:
So I then spent the weekend reading that. I was like, “Should we boot the Oasis in Salesforce?” He was like, “No, let’s wind ourselves back.” So it was Visualforce, 3JS, and it was platform events as well, which were …

Josh:
Oh, was it really?

Paul Battisson:
Well, no, not platform events. It was the streaming API, which was honestly slightly a precursor. So we had a demo where we had all these people in the lecture hall or theater, and one of us was wearing the Google Cardboard. We had a beach scene that you could see around in 3D, and we had a webpage, a sites page, that people could go in and just press a button, and it would create a record as the guest user, and that was connected to the streaming API, and every time the [Comet 00:20:24] D interface received an event, it would create a firework. So we had these fireworks just going off around in your head, based upon people. Yeah, there was quite a nice thing at the end. We basically said we’ve got five minutes for questions, but we’re just going to stand here, and anyone who wants to play … So we just had this queue of people. I think this was before they were really recorded, so it worked out well.

Paul Battisson:
Nowadays, there’d be a guy at the back on the AV just telling me to shut up. It was great. We had a queue of people, they came up, were playing with the Cardboard. But it was also quite nice and simple tech. The streaming API, nice and simple. [Comet 00:21:05] D isn’t the easiest thing to set up, but it’s not too awful. Yeah, it was just some nice recourse coming in, and that was it. There was a couple of really good VR demos that year. There was one company who were doing almost like a stack of cylinders, where you could go and choose different records and view opportunity data and things like that. I think that’s the … It’s one of those cool, fun things. Vinny and I just enjoyed working on it because we just enjoyed working on it.

Paul Battisson:
It made my mobile phone, my cell phone, overheat. It genuinely was. Could not put that in my trouser pocket because it was burning my leg.

Josh:
Oh my gosh.

Paul Battisson:
And drained the battery, but there’s no use-case for it. There’s no standard sales cloud VR use-case I can think of.

Josh:
Right.

Paul Battisson:
Product visions and things like that, maybe. But no AE is really going to use that and run it from their phone.

Josh:
Yeah. And that’s kind of my follow up question, because I remember people putting 3D analytics together. I somehow failed to see your … I honestly thought I was the person who put you on stage, but I don’t remember fireworks, so either I was, and you got that past me, or what. But then also storefronts, like a virtual store, people could walk around. I remember one, you could rotate an engine so you could see a product that normally you wouldn’t be able to hold in your hand. At one point, I thought the inflection point for VR was going to be that. Big business will throw money at VR and Oculus will do enterprise-grade headsets that the normal consumer isn’t going to buy, but the guy at GM who needs to work on the engine, he’s going to put a VR headset on. But it feels like we’ve gotten the opposite. Right? We have PSVR. VR gaming is having a hey-day right now, and it feels like enterprise VR just kind of fizzled out. Where do you think this is going?

Paul Battisson:
I think the reason that gaming kicked off earlier is it’s such an easy mass-market for people to go for. On the PSVR, there’s a game called Vader Immortal, and it’s done by what was formerly Lucas Arts, and that game. If anyone has a virtual reality headset and wants to just play an amazing experience, it’s that. It starts with you jumping out of hyperspace in a ship. You’re in the cockpit, you can see all around. My fiance came downstairs like, “What are you going wow about?” And I’m just stood there going, “Oh my god.” They knew what they were doing. They had Vader. It was with the ILM team, so Vader is always above you. So it doesn’t matter how tall you are, if you stand up, Vader is always looking down at you, and he’s a big, menacing … It was really cool. That’s an easy good experience to do in VR.

Paul Battisson:
Whereas, I think the problem with the enterprise level is it’s the cost barrier to see it. Training is a good example. I used to work with a lot of farmer companies. I could see it for surgeon training, all of those sorts of highly detailed niches, but the accuracy is not … If you’ve ever used any of the VR handsets, the accuracy is not there. There’s a reason that Surgeon Simulator on all these VR games is about you accidentally killing people on the operating table. If you can’t do that level of dexterity, it limits the things you can do.

Josh:
That’s fair.

Paul Battisson:
I suppose it’s like with that cost barrier, a big one was BMW or one of the German car manufacturers was saying you can sit in a BMW and style it the way you want. If I’m spending 30 to 40,000 pound on a car, I’m going to sit in the damn car. That’s the difference here. I think I can see there being more in the enterprise in the future. I thought Hololens or Google Glass was going to be it, because I can see it being an augmentation of your view, but I can’t see it being a complete VR setting.

Josh:
I feel like Microsoft agrees with you. They seem like they’re pushing ahead with Hololens.

Paul Battisson:
Yeah, they gave me a call just to check what I thought about it.

Josh:
I love it. So talking a little bit more about Weird APEX, you also have a series of short videos talking very specifically about performance and loops. I love how detailed you are in them, because they’re very … You’re very specifically showing apples to apples, and the distinctions between the apples, and what happens there, and my first question. One of the first things you do is in an iterator that is going to track array dot size, you move that array dot size into its own variable, and then you iterate against that, and you show a pretty significant increase in performance in that. First of all, I’m surprised. I’ve never tried that, I guess because I never assumed it would be that much of an increase in performance, but why is it? Is it just be cause size is that slow?

Paul Battisson:
Well, it’s not that slow. It’s the scale of it being that slow. So the loop videos were actually, they came first and then I did the machine learning talk, because the machine learning stuff just uses that and batch APEX in the background, I’d love to tell you it was something super cool. We were running loads of batch. The demo at Dreamforce, we basically got on stage for a 40 minute presentation like, “Okay, we’re going to start the demo now, [crosstalk 00:27:12] It’s Dreamforce. You don’t know if you’re going to be able to run 2000, because some of them are like 2000 batches that you run. And it’s looping, because you have to do all the maths.

Paul Battisson:
Yeah, we were using that, but the reasoning behind it was that I had realized that I got overly comfortable with the less syntactical [sugar four 00:27:38] loops that Salesforce gives. For account A in, and here’s my [soccer 00:27:45] query, and I’m off. It was one of those things that I’d got back into doing more JavaScript, and was just writing these loops the other way. I was like, “I wonder if they’re faster?” Just one of those things that came up, and then I saw the change, I was like, “Wow, this is a lot faster.”

Paul Battisson:
I think that’s it. If you’re doing a loop over 200 records, this isn’t going to make that much difference one way or another on things, but when I was starting to think about 10,000, 20,000, you could be iterating over thousands of things. It makes a big difference.

Josh:
So, do you have a feeling for where that tipping point is from 200 to 10,000? When is it really going to start making a difference?

Paul Battisson:
This is where I give the consultant’s answer of “It depends.” I recently did a talk at London’s Calling, and there’s a section in one of my books on this whole performance stuff. That’s a detailed description, performance stuff. Sorry for the jargon, folks. But there’s so many things in Salesforce that you can make fast or slow. I’m going to say Flow and Process Builder, they’re going to slow you down. It’s nothing. I don’t dislike Process Builder and Flow, but if you add a ton of them in there, you’re going to get five, ten second wait times for the save. That’s life. You’re going to be able to build things a bit quicker, but …

Josh:
So it’s a trade-off.

Paul Battisson:
Exactly. And the trade-off is the key thing here. If you do that different four loop, you’re going to end up taking up heap size. Now, the trade-off really is not just [inaudible 00:29:35], it’s what are you doing within that four loop. So just doing something dead simple, it’s not going to matter. It’s going to be milliseconds. But if each one of those four loop iterations takes half a second or 100 milliseconds, that’s when it adds up. One of the things I try and focus on when I’m talking to people about performance is that I love sitting and looking at graphs, and getting nerdy, so look, here’s a parabolic, and here’s … In that book, I go into [big O 00:30:06] notation analysis and all sorts of stuff like that, but at the end of the day, does the user notice it and does the user care? So heap size is a great example.

Paul Battisson:
If you said to me, “Paul, you’ve sped up the CPU processing by … ” Say I’ve taken it from five seconds to one. But I’m now using … I’ve gone from consuming five percent of my heap size to 65% of my heap size. That’s fine with me, because my end user doesn’t care about my heap size. I assume that Chris Peterson or someone back in Salesforce is probably sat there going, “What’s he doing? Why is he doing this?” You know, getting very angry with me. But my end user is going to notice five seconds down to one. They’re not going to notice whether it’s two megabytes or seven. Two megabytes or four megabytes of heap size, they don’t care.

Josh:
Right.

Paul Battisson:
That’s the thing here, as you say. It’s trade-offs, but it’s also understanding what really matters, which is what’s the user going to notice?

Josh:
Right. First of all, I know Chris well, and I think it’s true, he does take other people’s code very personally. Just kidding. Okay, I’m going to ask you what probably sounds like an on-the-nose question, but I’m asking this because back in my Visualforce workshop days, I knew there were a lot of people who knew Visualforce, but didn’t know what a view state was. So define heap size for me.

Paul Battisson:
Oh, heap size is the amount of stuff you have in memory, is my simple explanation. When I’m doing the Salesforce training things, it comes up, and you can either go into a really deep dive, or simple answer. The amount of stuff in memory at the time that you have called up.

Josh:
Well, I think that’s an interesting comparison, because that’s also the best explanation for a view-state. Right? This is the amount of stuff that your client and server need to talk to each other about, and the less of it there is, the faster your pay is going to be. I think that might actually answer my next question, then, because the next thing you do is move an array into its own variable, and then reference the variable. Is that changing the heap size? Is that why that’s faster?

Paul Battisson:
Yeah, so that increases a lot of heap size. It takes up more heap size, but has a change in your CPU performance, and that’s again the see-saw of … Obviously, if you end up going over the heap size, that’s also a governor limit.

Josh:
Right.

Paul Battisson:
But are you going to?

Josh:
But are you going to? Well, I think … I’m trying to remember if it was in these videos or in one of your blog posts, you had a really good analogy that’s like, governor limits are there to keep Salesforce safe. They’re not a predictor of performance, right?

Paul Battisson:
Yeah. Because you’ve got 100, 100 [inaudible 00:32:51] is not a target. That is a limit, not a target. Same with … The heap size is the only one that is so different, because it is … The only time I’ve ever hit the heap size is when I’m messing around with blobs.

Josh:
Right.

Paul Battisson:
It’s such a weird … APEX is obviously, for want of a terrible phrasing, is a DSL on top of Java. I know it’s not … Chris, I’m so sorry, if you’re listening to this. APEX compiles down to Java byte code. It’s great at memory management. The JVM [inaudible 00:33:32] spin up, once it’s spinning, it’s fantastic at keeping memory clean.

Josh:
Right, it’s good at spinning plates.

Paul Battisson:
Exactly. And that’s the same. You’re using that same memory engine, effectively, under the hood. It’s going to be really good at cleaning things out, and there’s also some little hacks you can do where if you want to clear something, set it to null. It’ll reassign the address, [crosstalk 00:33:55].

Josh:
Yeah. It is. I mean, data management comes up so many times when we’re talking about how fast can we get acts actually done. Now, that video is followed up by something I’ve personally found delightful, because apparently you got into a Twitter conversation about what you were doing performance-wise, and then you had [Anthony Fawcett 00:34:18], Andy [inaudible 00:34:20], and who was the third? [Steven Harrod 00:34:22]. You had [Steven Harrod 00:34:24] all being like, “Well what about this? Is this faster or what about this? Is this faster?” I’m actually going to leave as homework to our audience to go watch that other video, because I think it’s a fascinating batch of really smart people offering really smart designs kind of things, but I will just note, I am not surprised that the most complicated offer was from Andrew [Fawcett 00:34:49].

Paul Battisson:
No, Andy was my first boss when I started learning Salesforce.

Josh:
Really?

Paul Battisson:
Andy and I used to sit 15 feet from each other. Andy taught me a load about APEX.

Josh:
Wow, nice.

Paul Battisson:
Andy is one of the smart … I was very, very lucky that when I started out, I was learning from him and [Steven Willcock 00:35:08], who is still at Financialforce. [Caroline Ruiz 00:35:12], and just a bunch of super smart … There’s idiot me, and all these clever people willing to give me time to talk through stuff.

Josh:
Right, right. And obviously I’m kind of jabbing Andy a little bit in the ribs. He is one of the most brilliant people I’ve met, and while complicated, I do think he’s a brave enough programmer to be like, “Just have your own iterator. Just try that.”

Paul Battisson:
Yeah, so having worked with Andy a lot, Andy is obviously the father of the APEX patents, and all that stuff that comes in. I’m one of these people that I look at them, and I can see everything that’s in them, I’m like, “That’s too much code for me to add.” I’m a lazy programmer. Keep it lean, keep it mean. But I know I can see the value in them, and Andy is exceptionally smart at coming up with that sort of stuff. It was no surprise that he made the leap to the mothership, because you guys have got yourselves just a super person there working on stuff.

Josh:
Yeah. And Andy, if you’re listening, we’re very happy to have you. Okay, you have literally written the book, or actually, technically books, on this. What books do you have out there and where can people get them?

Paul Battisson:
So, all good book stores, but primarily Amazon, because everyone gets everything from there nowadays. But yeah, I spent my lockdown doing two books on APEX, because I couldn’t go anywhere. So the first book is called Learning Salesforce Development with APEX. It’s kind of an intro book to APEX, so if you’re an admin looking to learn APEX, or a brand new developer to the platform, it’s designed for you. When we started, we were saying about learning Perl and learning C and learning [inaudible 00:36:54]. When I first started learning APEX, every piece of the documentation was like, “Just like Java,” or “Just like .Net” and if you don’t know Java and .Net, that’s not helpful.

Paul Battisson:
So it’s kind of a ground-up. By the end of it, you are calling a web service and doing all sorts of cool stuff like that. It’s going to take you all the way through that, and then one of the fun things you find as you’re writing a book like that where you know that there’s a definitive, “I can’t go past this,” is you then go, “But I want to talk about all of this other stuff.” So the second book is called Mastering APEX Programming. It is for intermediate developers. If you’ve got three years plus, hopefully you can learn something. I have to give a big shout out to Mike Gill, who was the technical reviewer on the book. I’m lucky enough to work with Mike every day, but he gave so much good feedback, and was really good at saying, “I learned something from this,” or “I’m going to tell you you need to add this in.” Which is exactly what you need.

Paul Battisson:
And it goes through different sections. The first one is very much almost like a how-to-program book, but specific to Salesforce. The second one is more like, okay, this is a bunch of stuff on common errors and how you get rid of them. How to debug properly and use the tools. How to just do stuff that people are perhaps … How to write unit tests, and how to use those unit tests to help you debug effectively.

Josh:
Got it.

Paul Battisson:
And then we go into asynchronous APEX, so all of the different flavors. How and when to use them. Again, if someone like Chris reads it, I’m sure they’ll go, “Eh, I’m not sure about some of these.” In my own experience, I would caveat this. Caveat everything that’s in every book by, “Do your own research.” Yeah, and then the last section is all about performance. Some of the things that you talked about with the loops, but I also get into query performance, different bits and pieces like that. How the force.com optimizer works, and then some impacts that architecture can have on it.

Josh:
And that’s our show. Now, in the show notes, we will have links to Paul’s books, and the various talks and presentations that he’s done. Now, before we go, I did ask after Paul’s favorite non-technical hobby, and it turns out it’s one that we both share with a lot of developers.

Paul Battisson:
It’s going to be probably playing on my PlayStation when I get the time. I have a dwindling amount of time, but I’ve got a couple of good friends. We play regularly. Bit of Ghosts of Tsushima and a few other games together.

Josh:
Oh, brilliant.

Paul Battisson:
Yeah, old school friends, old university friends just abusing each other for a couple of hours whilst, you know, [inaudible 00:39:34]. It’s good fun.

Josh:
I want to thank Paul for the great conversation and information, and as always, I want to thank you for listening. If you want to learn more about this show, head on over to developer.salesforce.com/podcast where you can hear old episodes, see the show notes, and have links to your favorite podcast service. Thanks again, and I’ll talk to you next week.

Get notified of new episodes with the new Salesforce Developers Slack app.