Overview

About this video

What You'll Learn

  1. Install and enable Xdebug with PECL, confirm extension loading, then generate profiler output from the PHP CLI.
  2. Capture traces hello-world and factorial scripts, then inspect Cachegrind call trees in QCachegrind to find hot spots.
  3. Profile Composer install in xdebug versions 2 and 3, then compare output and isolate Composer-specific profiling settings.

Derick Rethans walks through installing Xdebug via PECL, enabling its profiler, and reading the resulting Cachegrind files in QCachegrind to find hot paths, starting from hello-world and factorial scripts before profiling Composer install on a real project.

Chapters

Jump to a chapter

  1. 0:00 Holding Screen
  2. 1:55 Introductions
  3. 6:30 What are we going to profile?
  4. 11:30 Installing and enabling Xdebug extension with Pecl
  5. 17:40 Profiling our hello-world example
  6. 28:20 Profiling our factorial example
  7. 46:20 Profiling our simple composer configuration
  8. 57:30 Profiling our complex composer configuration
  9. 1:09:00 Compiling Xdebug 3 for the performance gains!
  10. 1:13:00 Profiling our complex composer configuration with much gains
Transcript

Full transcript

Generated from the English captions. Timestamps jump the player to that moment.

Read the full transcript

1:55 Introductions

1:59 Hello, and welcome. Thank you, Derek. I will pop that on the screen. Thank you. Today, I am joined by Derek Ressons, the author and maintainer and all around nice person surrounding xdebug. How are you, Derek? I'm good. Yourself? It's been a beautiful day today. It has, which has made my video set up a little bit more difficult than I wanted it to be. But Yeah. I've been I've been hacking on SSL related the whole day, so there we go. Oh, nice. Any nice long walks today? You've been walking the chip station. Right? Oh, yeah. Not today. That's usually a weekend

2:39 thing, so that's back for Saturday and Sunday. Yeah. Plan is to walk the length of all the London tube lines. Yeah. No easy things there. Yeah. It's just not it's not hard. It just takes a long time. Yeah. Yeah. So today, you've very graciously offered to join me and teach me how to profile PHP applications with xdebug. Right. Alright. Excellent. So before we get started on that, what I would like to do is say that we do have a Discord where people can come and chat and leave questions. You are also very welcome to leave questions on YouTube.

3:22 However, if you are feeling brave and you wish to pop into the stream and join us live to ask your question and have a short discussion, then we will try and fit that in towards the end. If you wanna do that, drop me a message on Discord, and we will try to sort it out. Now to get started today, we need my screen to be shared. And we will do this. And by the power of magic, we are in. So I'm starting off with a pretty sorry. Did you say something there, Derek? No. I just need to make sure that

4:00 I increase the font size on this because I can't read that. There we go. That's a bit better. Yeah. So the font size on the sidebar, I do not know how to make that bigger without zooming in on the whole thing because I think it's, like, an electron app. I can't remember what code is. But the text editor should be nice and large for us. Yes. That I can write. Excellent. And, hopefully, your terminal's as well. Yeah. My terminal Oh, that's easy peasy. You know, I've I just now leave it like this all the time. So even when

4:31 I'm coding on my own and it's not for a stream, I just present it with this massive text. And you know what? It's it's oddly satisfying. Like, I don't need to see 14 functions at once. I just need to see see what Yeah. It's true. And that is, like, funny how that goes. Let me actually put my face in your whole screen because you've cut me off a little bit. There we go. Oh, hi, Ruth. Sorry about that. Been live moving your face to the center of the screen. Pretty Now you can't see my lovely backgrounds.

5:00 We can see better, but don't worry. I can I can see it? Okay. So I'm starting from a clean slate today. Anyone who's watched the stream before will know that I have a lot of PHP experience, but I haven't really got any modern PHP experience. I haven't really written a lot of PHP in the last four to five years, which means that my computer setup right now comes with whatever the Mac gives me. I have PHP 7.3, and I installed Composer through brew. But I haven't done anything else. Nothing else is done in advance of this session.

5:34 Do you have any home brew setups or not? I do have homebrew available. We can install anything that we need to get going. Yeah. So get rid get first thing I would always recommend, get rid of the PHP that comes with the Mac because I don't know what they've done to it, but it doesn't behave as it should. It doesn't behave as it should. Okay. Even tells it even it even tells you when you type PHP. Right? So yeah. Because I'm also running Big Sur, living life on the edge, it now says PHP is not recommended. But I think what

6:03 they actually mean is is no longer gonna ship by default with the next version. So it's a really terrible message or some developer having a very bad joke. So can I just do brew install PHP? Yes. I think so. I don't use a Mac. I'm just guessing it. I don't really use a Mac either. It's something that I took on as part of my new role with Packet, and I'm still very much getting used to it. I mess my tiling window manager. That's for sure. Yeah. Okay. So let's go over the plan of that homebrew that's just breathing. Okay. So I've

6:30 What are we going to profile?

6:39 okay. So I lied. I have said a couple of things up. So when we were talking I got a fear yesterday, Derek, I should say, when you tweeted me saying, I hope you've got a slow PHP application. And I was like, shit. I never thought about what we'd actually profile. So I got my thinking hat on. And I figured we could start with a really trivial trivial example where we would Right. Run the pro profiler on a one line Huddl world application. Mhmm. I don't think we're gonna lot out of it, but I think just to see

7:08 the tooling and the setup and a simple call graph may be beneficial. At least for me, I wanna see it in the simplest form before we break it with the the harder stuff. And then I thought about how can we make it a little bit more interesting? And I thought, well, recursion is generally interesting when it comes to profiling. So I created a very small factorial function that is recursive, and we can throw some different values into this. And I thought, depending on how we get on with that really, I should have run this plan be

7:37 for you beforehand, but we'll just do that. I thought we could inject some arbitrary errors where we add a sleep. Now we're looking at this now, but I thought if we can I I want to see if we can use the profile to identify what is causing certain bottlenecks rather than just is the factorial function randomly coming out of that time? I don't know. It just Yeah. We'll see. Do you have the profiling front end installed? You didn't think about it either, did you? Versus Code, I'm assuming it has some sort of front end. Nah. It's got a deep

8:14 Oh, yeah? No. It doesn't do profiling front ends. Luckily, I have a homebrew formula for you there too. Okay. Alright. That's how just googled. Okay. The next I I set aside four examples. The next one being, I figured we could do a composer with a really small composer JSON. You can see I just got two packages here, and we can actually profile composer itself before tackling something much larger. Now that's just a project I found on GitHub called Zulu. It seems to be like a CMS system built on Laravel or Symphony. I can't remember. It's Symphony.

8:50 And it has a lot of dependencies. At least, it's quite hefty. And I did run a composer install before this and then blew away the vendor folder and the log file. It took around a minute, I believe. So, hopefully, that gets us something substantial that we can take a look at the call graph and the profiles, etcetera. Yeah. It's usually the the the having the caches available is not usually the problem because that's you're just waiting for network IO, and who cares about that? Exactly. I'm more interested than the dependency graph resolution and how long that takes. Yeah. So

9:20 for that, it's actually better to have the cache in place, but we'll get there when we get there. Excellent. So what do I need to do first? Alright. Let's have a look back at your terminal, whether you actually have PHP going now. We have seven five four dot 10 just coming down the pipe now. So Alright. If you wouldn't mind starting another terminal where you can add some more things Indeed. Then we then it can run that while we when we do actual things. Okay. So there's a home also brew install, and then it's called q cache grind.

10:02 Q? The letter q and a cache grant. Cache grant. Grains? Yep. No. Without yes. Cache grant? Yep. Is that all? Yep. Well, whether works is to be seen, but So what is this that I'm installing? Is it front end for for xdebug specifically or profiles in general? It's actually not specific for xdebug. The profiling format that xdebug outputs is actually something that comes out of Vellgrind's tooling. Vellgrind is like a low level memory profiling CPU emulating tool that also allows you to make profiles of c programs or c plus plus programs. And because I don't know how to write front

10:52 ends, especially not nice looking functional graphical front ends, I just saw the formats for xdebug so that it uses the same. We don't really have to look at this. For now, we first need to get the profiler going. So just let it sit in the background for a while, and let's see what we're going on. Alright. So Okay. That's still that's still the wrong one. Right? Because where did it install PHP? Where did where did Brew install it? May want me to do a BrewLink. Okay. Oh, in fact, it probably just wants me to pop open a new terminal, doesn't

11:28 it? So Yeah. So this is the intricacies that I don't really know. Magic. Right? There we Okay. So is is peccl available with this or not? P e c l. Can you just type in and see what it is? Otherwise, you might yeah. Excellent. So peccl install xdebug. And this is me installing the PHP extension xdebug. Right? Yes. Yeah. There used to be homebrew formulas for all the extensions, but I stopped doing that. So you now have to use peckle to install these things. You got a few errors, but you just ignore them. That's great advice in general, I feel.

11:30 Installing and enabling Xdebug extension with Pecl

12:10 It's just this is this is the the so maxed out themselves as being Unix, but it is kind of weird. But, yeah, now we have to wait for it to it's So I have I have anticipated us running into some sort of Mac issues, and I did spin up a Linux machine on Packet Cloud just in case we need it. So So there's somebody asking at chats, would that grind Docker container would also work as good as key cache grind? I don't think so. I think that grind is good for oh, fancy. You got the questions on here. Yep.

12:49 So the web client is also a useful tool, but it is not nearly as powerful as q q cache client or the two the variant that I use is called k cache client, which is the same tool but with a slightly different looking from that. The k stands for k d e and the q stands for QT. Of course, as you know, KD is just a shell around QT or QT or whatever people want to pronounce that. But, no, I I don't think a web client container or web grinds in general is as nice or as useful as

13:21 q cache grinds or cache cache grinds. However, it's a lot easier to pronounce. I'll give it that. Alright. Did it did it install? Yes. We have both available now. We have two cache grind, and I have xdebug enabled in my PHP. Can you minus v? Yeah. Just do minus v. And it's e? V for v. Yeah. It shows up. Excellent. Now the only thing that you might have to be careful of is that xdebug is loaded after opcache. And in your case, it's loaded before op cache. Now this shouldn't cause any problems with profiling, but I would

14:09 advise not to have them this way around. Okay. So do should we change that in the PHP NA? Yeah. So if you type PHP minus minus I and I, two minuses. It'll tell you which files it loads, and you see that what's has done is installed it into PHP I nine, but it really should have put it in a separate file like x op cache has done. I don't I don't know what the two doesn't do that. So what we need to do is Put it there. What we need to do is remove it from PHP

14:45 I nine. At the top. It's at the top. First line. Delete delete this line, and I'll leave just save the file. And now create this new file that is called x dash xdebug. Not any. Yep. And then the thing that you just removed, paste it back in there. Okay. Z zent underscore exten extension equals xdebug. I would not recommend spaces or quotes. Think so? Get rid of the quotes. Don't don't need them. I love the reason why I say don't use quotes is because people copy and paste this from websites, and invariably, the quotes have been replaced by

15:51 the curly quotes, and then it doesn't work. So I would always say, I I I do the minimalist approach. If you don't need it, don't enter it anyway. PHP minus v should now have it the right way around. Ta da. And I'll verify whether that's what it does here. There we go. So, ideally, the tool knows about these things and does these things right, but it doesn't. That's why I think the homebrew formulas also have been kept because they'd handle these things correctly. Anyhow, it is loaded. Excellent. Now we just need to enable the profiler.

16:34 And how do we do that? Open up the any file that you've just created Yep. And add the new line saying profiler. Sorry. Xdebug dot underscore enable equals one. And if you now type a PHP minus minus r I xdebug no. With a space after the I. Sorry. And as if you scroll up a little bit, you can so the line that I was interested in, scroll three three or four more. There we go. So it tells you the profile is on, what the output directory is, Is that a valid directory? Yes. Type it. It's empty. Even better. Okay.

17:40 Profiling our hello-world example

17:40 So now if you request your PHP script, it should create a profile file. So if you type PHP, space, the name of your scripts. I'm not in the record. So I go into my hello world directory. Yeah. And I can just do PHP main dot PHP. Yes. By magic, I have a profile. Yes. You have a profile file. Exactly. Now what I if you do this for websites, I would actually recommend you turn on the trigger and stat and install a browser extension, but we might have a look at that later Yeah. Sure. If we have time. Any case,

18:16 we have this cache client dot out file. Do you want to open it? Let's see what's in there. Barack dev cache client. K. Well, what do you see here? I see the command that was run on the scripts. I see oh, so it's got some events, which I guess are the function calls with some numeric values. Okay. So the the numeric values are basically an index number so that the next time it sees the same file, it wouldn't include the file name and just include the number. It's just a clever way of basically, like an index creation,

18:58 but it's doesn't matter. It's just a way of the format works. And then we have the one one eighty eight and thirty two. That's basically stands for line one. It took a hundred and eighty eight microseconds. I'd hope it's not milliseconds for Hello World. Yeah. Microseconds. Microseconds, and then it took 32 bytes of memory. And then you get the summary that it the actually, whole full execution took one dot four milliseconds, and it took 431 parts parts of memory. However, this is not how you'd look at these files. Right? And you just want to make sure that the

19:38 first time you do that, we have a look at this to see what is actually in here. But the way how I would view this is by using q cache client, or in my case, k cache client. So you can q cache client, and then specify the file name behind. Alright. Stuff. There we go. Yeah. Okay. Can you make this bigger? I also don't know how to zoom in there. Is this not something that your your operator system provides? So I could do this. That makes it weird. That changed absolutely nothing. Anyway, yeah. We'll try to make it work.

20:41 Can you at least make it full screen now so we don't get distracted by QCache currents error messages? Oh, dear god. This is small. How do I make this bigger for myself so I actually can see it? So maybe just an electron, file grain, cash grain thing that we could use, which would allow me to zoom or maybe a web one that can open. Anyway, I've yeah. I if it's full screen, it works for me. I can just about see this. But, yeah, there's not a lot of information in here. And on the so on the on the left

21:15 hand side, you have all the function calls. When this case is only main because yeah. There's sorry. Because you didn't call any functions. On the right hand side, you have a few tabs. If you click on source code tab, this is fifth one, you can actually see your source code. So that's handy. But echo is not a function call, so you can't really see anything in here. So it doesn't really do it show you it can't show you more because there's nothing to show. And so our the echo on a function call? Just Yeah. Sure.

21:58 Absolutely. Okay. So what we're saying is that's not very interesting, but if we do function my echo string oh, I can do this there. Right? And then we could do echo string. We could do that since PHP seven zero already, which has been out for five years. Okay. So if I Yep. Run this again, we'll get a new profile. Yep. And we can open this. Yeah. It's open. So there there's actually a trick that it doesn't change the file name because at the moment, it uses the process ID Okay. Which is what's cache client's standard way

22:49 of doing things are, but you don't have to do it. And there's ways of changing the output format so that if you run it from the same directory, it will always be the same file if you want to do that. Yeah. It may make it a bit easier for today. So you'd be typing down this a lot. Okay. Open the any file again then. Okay. User You does control r does control r So I did, but the problem is I have pair director history. So I need to go up and then do them. Oh, okay. So that is usually a feature,

23:29 but not at the moment. Yes. So the setting is xdebug dot profiler Profiler underscore underscore outputs underscore name Yep. Equals and now you cache dot out dot I wasn't quite done yet. Don't go ahead of yourself. Dot percent c. So the thing the thing behind the percent sign is a form of specify, and the documentation lists a whole bunch of them. The c stands for the CRC 32 of your current direct working directory, Whereas by default, b two p, which is your process ID, but there's a whole bunch more, such as the full the like, the the h t p URL,

24:25 for example, if you want. So that means that if I so I could have done that without the percentage to you. Right? But it means if I changed directory and profiled something else, then I would overwrite that last profile. So this incorporates the file name or directory path into that. Is that right? Just the directory part at the moment. Yeah. Alright. Okay. But, yeah, you can also do the parts and other things. There's there's a whole bunch of settings if you want to look at the documentation. Yep. Okay. So if I run that again Now you should have, of course, the third

24:57 one Yep. Which is to but that one will never change. Oh, once you run it from this directory. And now you as you can see, you have two functions. Right? Yes. We do. Okay. So our source code is gonna be updated, and we have two calls over here. So we've got main followed by the my echo. Okay. Cool. Right. So there's a few interesting columns here, which will be more interesting once we have some more function calls. But on the left hand side, you have includes include, it says. All the way to the left. All the

25:32 way to the Yep. Yep. Yep. Okay. Yep. Include. In Incl stands for inclusive, not include. Inclusive. Okay. And self stands for self. So, basically, what these things mean that inclusive means all the time spent in this function and all the functions it has called, whereas self says only the time spent in this function. So theoretically, in simple examples, if you add all the self times if you add them altogether, it should end up at a %, which Which it is. At the moment, it does. There is, of course, often rounding errors in there, and there's recursion in there that makes

26:10 that not work. But in a simple example, that should all add up to a hundred because, well, you can't spend time twice. Right? Okay. Makes sense. Okay. And then on your right hand side, there is for example, click on map. K. Yeah. And now something doesn't render for me correctly because the whole screen should be blue. So the left hand side, which looks white on the preview, is green for me with a little bit on the blue. So it's like the that seems to represent the self values mapped out with colors. Yep. Pretty much true. So this is a

26:53 way of seeing in one overview is the things that have a large area stacked on top of stuff is where a lot of time is being taken. So in this case, what you would expect, 80% is spent in just main where that is mostly overhead of parsing it, to be fair. And then on the and then the 20% should be the the blue bit that is then the my echo. Yep. Perfect. And if we have more interesting things, we can see more interesting information. But there you go. Now on the bottom half, if you click on call graph

27:28 all the way all the way in the bottom. There we go. Let's hope that works better. Just check if click on call graph. It's working for me, but it's not updating on. Oh, I just have to change change screen and then magically Hey. Yeah. Yeah. Sorry. What can I say? Yeah. I've never seen that issue before, but, hey, now we know it, we can work around it. Yes. But, yeah, you can see the call graph. Basically, you see in the graph which functions calls which function, how often and how much time we'll spend in these functions.

28:06 And that, once we have something more interesting to show, will tell us what is taking up the most amount of time or what is the the slow path to be to be precise. So shall we find a example that is more interesting than hello, world? Sounds like a good idea. I agree. So if we take a look at our factorial You need to do the screen search thing again. That is peculiar. Okay. How about my factorial functions? That should be look. You mentioned the recursion this week. He went through the hello world from there and

28:20 Profiling our factorial example

28:48 said that the values may not add up. So I guess I was fortunate enough that I had some recursion. Would you please alter braces around the return? No. The top one. The ones in line five and seven. Was that new either? Is that personal It's also not changing, by the way. Well, that is let's just turn off my screen share and then reshare. That is weird. You can't admire the Tower Bridge at night for a moment here. Alright. So if I yeah. Okay. I think we're okay. So not a personal well, yes, personal preference, but

29:40 in the xdebug version that you still run two nine with all the PHP version that sometimes gets line numbers on the wrong places. And Okay. Hence, step debugging and profiling looks strange, although it is something that PHP internally does. So I would always suggest to other braces. It's also what in is there in most coding standards. Alright. Good to hear that. Good. Yep. Alright. Let's run it. Pick a number. 721. So because my PHP is a little rusty, I wasn't sure if it read an input, so I have just decided to pull it from the environment,

30:27 which is why we're using this sometime. Okay. That's brilliant. Is it? It looks like an error. K. Scroll up. Let's see what you've done. Oh, it's because I've not casted it to an end. Although it worked when I made Oh, yeah. Yeah. Tested this code. That's not how you cast it in. You you do in in between parentheses in front of what you're casting. It's not go. Are you sure it's not go? That's that's what I write mostly these days. Okay. So to catch I know. I can tell. Yeah. Put in put in in parenthesis.

31:14 And and oh, like c. Like okay. Got it. Yes. Like c. There we go. That's how you do that. The first if if that's one is true, factorial of a negative number as one? If less than or equal to one, return one. That's okay. Okay. I think so. Let's run this. Index number. I can test this through the Let's do the proper way. Okay. Open up your PHP file. You're just doing this how how does she how you should do this. The number is the int cost of arc v one. Yeah. And then arc v yeah. Exactly. Don't forget

32:04 your semicolon. It's not go. So now you just have to pass that 721 here. Right? Yes. That was a Okay. Well, you have a bug in your code, mate, because this is xdebug telling you if you see the whole error message, pipe what you type to to less and you'll see what I mean. There's 250 lines you don't want to scroll up. So I only tested the small numbers, and it works. So it's the big number that's causing the error. Okay. So let's run over seven two one and put errors to log. Correct? Yeah. But that will

32:48 it's standard output. So we'll move it to you. Maximum function nesting level of 256. Yeah. You know what that means? Well, I was assuming that this was tail call optimized, and that would be okay. But I'm assuming It's call optimized. What do you mean by that? Can we disable xdebug for a second? Yeah. Sure. And then it'll just you don't have to disable it. Just type minus n on the command line. PHP minus n and then the rest of your line. And for Yeah. And would you now make this number how can it be inf? That makes no

33:43 sense? So what is the highest number you can do? Yeah. It's just the numbers are too big. Okay. Let's just stick with smaller numbers for now. Let's not break it. Let's run back and Wait. Say I yeah. I was let's pick seven as a good number. Okay. Now let's let's see how big the file is that this has created. Okay. So we wanna do l l bar 10. We must be this one here. We'll take human readable side of this. That's not that well, let's just go what is the human readable of 734? It's because I'm not actually using alias, so

34:39 that's an alias for something else. I think I think so let's just the old school It's still going to be showing '3 and 07/1934. Yeah. I yeah. I'll quiet. Do you want to open up the file? I don't know because I'm getting loads of things wrong here. Maybe we should just quit while we're ahead. There we go. There we go. Yeah. Alright. This makes sense. Right? So on your left hand side, you still have two functions. You have your main and your factorial. Also, the self columns added up together end up at a hundred, so there's nothing wrong with it.

35:25 You can see that spent time in the factorial function is now more. It's now six it's 60 ish percent, and your color graph says that factorial calls itself six times, which makes sense for the number seven. Indeed. Now there are a few other things in q cache client. So at the top, you have a few icons. So you have the open file icon, which lets you open a new file. You have the the one next to it, the text cycles. So that is the clever bit in QCache Grind that's if you have a cycle like this, like

36:00 a recursive function, it the it's can detect that and will then analyze things according to the cycle. So if you get recursion, it's difficult to create a graph because you never know how you end up escaping the recursion. Right? I mean, in your case, you can't really see this because factorial itself doesn't do anything else except calling itself. So there's no no issue of it having to be detected because there's no other output part out of factorial. But if factorial would have called my echo or done something through another function, it will show you these cycles as well.

36:46 So if you create a function, my factorial, that's called factorial and change change that in your scripts, then it's a number. Yeah. And that just calls factorial. And then on line 17, you change factorial to my factorial. I mean, could we also just add an echo that says hi with that? Yep. Echo echoes and function calls. Alright. Gotcha. So if you want to do that, you can use a a print f, for example. That would work, but echo doesn't. Exactly. I like two lines. Okay. Yeah. But I never bother a I never bother with a constant. I just type slash

37:47 n. Alright. Will we feel brave while we do 21? Yeah. Sure. Alright. Okay. You should get this 21 times. So that's not so bad. Do you want to check this file size just to see how bad that can get? 3.9 k. Yep. The false can get big. Yep. Be aware of that. Anyway, let's open them in QCachegrind and see what this is. Woah. You're making pretty pictures. This is awesome. Yeah. Cute cash grind, I think you should take a screenshot. This is this is why people use factorials to do random cool wallpapers and stuff, isn't

38:30 it? Because you do get all these weird recursive looks. It's amazing. Alright. We'll take a screenshot. We'll put it on there. Should not that. Okay. Yeah. Excellent. But, yeah, now you see a cycle. Right? You see a factorial my factorial 19 times, but there's some other interesting that happened as well. Look at the percentages. Oh, 642% versus 582%. Which makes no sense. I mean, you can argue that main is a little bit larger because of routing errors, but that's old, isn't it? This is this is a bug. It's a bug, an xdebug, but I haven't figured out how to fix

39:19 it yet. Okay. So we could skip over that for now. I don't judge. I don't judge. It does not particularly matter though because it still allows you to detect the slow path. But in this case, there's so little information to slow. We know what the slowest part is because it's just calling the function over and over again. So can I slow it down with some crappy code? Yes. Or do wanna go over this first? Is there something here that we should Yeah. I want to point out a few things. Okay. So the icons that I was just talking about,

39:50 the first one is detecting cycles. Just click it off. K. Of course. Now you need to resize the screen, I think, because it should have changed information, and I still see the same thing. No. It's not changed on my side either. Can I refresh? No. No. If it didn't change, then then that's fine. So the cycle detection still didn't have to kick in here because it's still not interesting enough because you still only get a circle. This is something that is going to be really hard to artificially create, so I wouldn't bother trying it. We will

40:27 see this when we run something interesting like Composer because Composer has a recursive dependency solver in it. Okay. So the the only things to I want to point out one more thing. If on the top right tab, you go to all colors. Yep. The top right. Oh, alright. Yeah. And you select k. Print f on the left hand side. It is interesting because it shows you the distance from other functions. So this sometimes tells you if this is all in one or prominently from only one other function, it pretty much means that it might make sense to inline it if it

41:22 takes up a lot of time. Because function calls sorry. Not a lot of time if there's a lot of calls there. Because function When you say testings, do you mean how many functions deep the call was? How many how many different levels, stack levels there were between the function that you selected and the one on that list there. Got you. Okay. So not necessarily from the top, but from well, in this case, main is from the top, of course, and the distance is always going to be two here, apparently. So to clarify that, if I had

41:55 a function, my my factorial, and I would also make this work, but that would be a distance of three if I updated these calls. Right? Right. Yes. Three three stacks, three function calls. Right. I think that if you would put the print f in the older function, it'd show you other things, but it doesn't matter. Anyway, recursion is the probably one of the hardest things to to actually analyze because things get confusing. But this makes sense now. Right? Yeah. Okay. That definitely. Yep. Shall we look at something more interesting? Can we slow this down first?

42:37 Does that change anything from a queue cash frame point of view? Will we be able to see the bottleneck of one of these functions? You will see that's the overheads of the function calls themselves goes away. So, yeah, I just put a u sleep in in my factorial. But I wanna say I only wanna do it. So let's say number is divisible by by then we do a use sleep. How long do you sleep? It's a microsecond. Yeah. Six hundred. That that's six hundred microseconds. Ah, you didn't We didn't return necessarily. So I don't think we were actually getting a

43:23 proper view of it. Right? No. We didn't actually check the output. Should have written a unit test. Okay. Let's let's try that again. That actually might mean that we didn't quite get the interesting output that we wanted. Yeah. Yeah. I noticed that maybe on back end. The position is 39 is we're now at eight k. But, yeah, it's definitely growing pretty rapidly. Yep. So if we take a look at wait. There we go. So now you see it as load. It's a little bit different. Right? But I'm I'm not sure why you got to use sleep every single time still.

44:07 Maybe my terrible coding? That looks okay to me. Yeah. It looks okay to me too. Okay. So if if we get 39, that would mean we should get eight calls to use, like I if we can Seven. If we seven. If we do seven, we should get less. So Click on there. Interesting. Yeah. I don't understand this. It still seems to be calling It seems to called five times according to this. That's correct. Yeah. And if you click on in a bolt, if you click on all if you click on colors of u sleep so select u sleep on the left,

45:04 and then all colors or colors, it says my factorial call that. So if you double click on my factorial no. Don't click away. I'm trying to explain things. And now go to source code. You can see in my factorial that there were five calls u sleep Yep. And 38 calls to factorial, which makes sense. Indeed. Now turn on back to cycle detection, because Doesn't change anything. That's so what No. Right. You selected a different function. Oh, sorry. No. You click on my pictorial, please. And then leave colors in the top right. Is there a question?

46:06 Do you, Crystal, raises a hand? Yep. If you have a question, you can type it in, and we will read out and handle that for you. No problem. Any in any case, I would like to see in something interesting instead of our contrived examples because then you can actually explain things. Alrighty then. Yep. So do you want her to compose her sample or go straight to the seller? Ask her to compose her sample first. Oh. No. Just saying hi. Hello. Hello, back? I can say hello in many languages. How about Mandalin? So you're not going to pick the language.

46:20 Profiling our simple composer configuration

47:01 I can pick the languages. How about Gaelic? Hello? That's simple enough. Alright. We won't make this a language lesson. We will No. Let's not do that. Because I don't want to be showing up as a well, terrible languages. So we have this composer dot json and I have put together with two dependencies. Now can I just run PHP composer install? I don't know why you have composer. It's just installed by brew. If it's installed by brew, I would like to see the first line of it. Yep. We can do that. Just type ahead and that name.

47:51 Oh, you can do it. Okay. So that should work. You need to make sure that the PHP is actually in the path and it is not. So that's what I wanted to check. User bin and PHP means it's in the path. Yep. Good. Alright. Run it. Okay. The first time, it's you said you wiped out the caches, so run this once more. Yep. Okay. That should be it. And now let's open a file with QCache client. Yeah. I don't know what name it is, but which one would it be? A lovely 66 k. So that's not so bad.

48:38 Woah. Yeah. That's interesting for the trivial or simple one. Look at there was actually a learning moment on the command line. Can you switch to your terminal? You see that? What it says there? Garbage at the end of the cost line. So this is something that has to do with memory profiling. QCache or cache clients' formats doesn't understand a negative cost, so it doesn't understand that if memory gets freed, you have a negative cost. So although memory profiling exists in xdebug, the visualization with cache client isn't always the greatest. Got it. So that's what I wanted to

49:23 point out here. So, I mean, right off the bat, this is, I mean, information overload for such a simple composer dot JSON. Well, composers and trivial code. Right? It's That that's true. Yeah. Exactly. How do we start to make heads and tails of this then? Yeah. Make it a little bit bigger that at the bottom screen. Bottom tab should yeah. Drag it up. Alright. So by default, what it will do is k, there will be another learning moment in a second. What it's what it will do is it will only show anything that's more than 5%, I believe.

50:06 But what is the interesting bit, if you follow the the the complicated parts, the one with the thick arrows Mhmm. What is the what is just follow follow it from the top to the bottom and see what it does. Just read out the function names. So we start off with main, and then we've got require far composer bend. Then we've got xdebug handler check followed by xdebug handler restart followed by xdebug hand xdebug handler do restart followed by a PHP pass through. Yes. What can what can you infer from this? The the complicated path is xdebug and not

50:48 not I don't know. So okay. That is a perfectly good answer. Let's find out then. Right? So if you click on the green well, the that says xdebug handler check. Yep. Double click. Sorry. And then at the top, select source code, and then scroll down. Oh, so this is annoying because it uses the FAR file. Do you want me just to open this? See that well, you can't just open it in FIM. Got it. But it says here I can add the folder of this file to the source folder list. Yeah. But QCat current doesn't understand far colon

51:40 slash slash as a file prefix. Oh, got it. Okay. See, I have don't have this problem locally because I run this. I run Composer not through the far file. I just have a checkout of it, but that's too complicated to do here. So although Composer might be an interesting thing to look at because we can't look at the source code, isn't the most interesting thing. But we'll explain what this is anyway. Basically, what it says is that what a check function does is it checks whether xdebug is loaded, and then it restarts PHP without xdebug loaded.

52:14 So the profile that we have is basically just a bootstrap, which then disables xdebug. So you don't get a profile of something interesting. You only get it off the bootstrapping thing that starts compose a bit where the interesting things are happening. Ah, okay. So Composer finds it necessary to disable xdebug. So if you want to profile composer, you need to turn off that behavior. Does that make sense? Yeah. So composer is xdebug aware and disables it because, generally, you're not profiling Composer but the thing that it's running. Well, the the reason why Composer disables xdebug

52:51 because they believe that it slows things down too much. Okay. So So how do we Let's go to the command line, and we basically, what we need to do is export a specific environment variable that turns off this behavior. So this is only something you're going to have if you're profiling a composer. Normally, you don't have to do this. So the thing to export is I need to look this up because I can't remember. It's composer underscore allow underscore xdebug equals one, all in capitals. Composer underscore allow underscore xdebug equals one. Equals one. Got it.

53:37 Okay. Now run it again. See, it now winds at you. Okay. You need to make sure check which files have been created because I think it has created two files. Nope. It's it's it has overwritten. It's okay. I just It is it must be good. Yep. So open it up, and we'll see again. So what's happened now? So here's something here, but it's changed the paths a little bit. Yeah. Click on main because it doesn't have a function selected at the moment. Oh, there we go. There we It's just stuck. It's stuck it's got stuck somewhere, and

54:34 I don't remember where. And now you actually got some interesting information. Right? Yeah. This this tree is much larger. The tree is longer. Yes. And if you go down a little bit so there, you see the cycle thing in there on the left hand side? Just yeah. It's just behind your see there? The cycle six where it says that? Yep. Got it. So that is your likely although I don't know composer code where it does the recursive loading of stuff. So there is some weird things in there that I don't know how it does. But the branch point where it goes from

55:15 one to three so if you go up a little bit in the in the tree, just scroll down here. So the do run basically calls five functions or five functions that we can see. One takes a third, one takes a tenth, and one takes a half, approximately. Yep. So you can see here, well, which two things take up the most amount of time? It's not the one in the middle. Right? It's that's only 10%, so we're not interested in that. But the thing that takes the most amount of time is the 52% here. Yeah. Let's say it here. Yeah.

55:53 So well, if you want to inspect that branch, double click on what it says there on the to run. And then you get to three further down. So the thickest line is always your slow path. Okay. So the the thickness of the line correlates to how much of the CPU cycles that execution took? Right. Okay. Yeah. Pretty much. And, yeah, well, let's go down and see where it ends up. I don't know. Composer and so but you see this the solver. That's basically what I was trying to get at. Yeah. So we come down to do install, and then there's quite

56:33 a hefty split where we go 6% down the right hand path. And on the left hand path, we're at 35% where the majority of that is 20% of some sort of dependency resolver rules. Yep. And then we have quite an even distribution across the next four calls, kind of four to 5% each. Yep. That's basically what it says. So there's probably not much that can be optimized here because they they know what they've been doing there. Because this recursive code is so critical to composer, they spend a lot of time optimizing that. So I think we struggle

57:12 finding a performance bottleneck in it. So True. But we do have a very nice way to to Exactly. Maximize that. It's like, you know, we can kind of see that call graph and and see where the time is being spent, which is really interesting. Exactly. So what I would recommend that we do now is we double click on this compose the dependence and resolve resolver solve to make that our our current note. Yeah. That one. And now we just leave this. Don't click on anything else. Just close q cache brand. Close it? Yep. Okay. And now let's go to your more

57:30 Profiling our complex composer configuration

57:48 complicated example. Okay. So we also The reason why I said don't click on anything is because it remembers the function that you have selected. So that allows us to compare between the two files. Okay. So from here, let me just make sure I definitely remove it. So there's no lock fail here, which means it's gonna have to build a dependency graph. Well, it needs to do that any case if you type composer update. What I don't want to do is have this guy on it. You're running composer of xdebug enabled. This has a major impact on run time performance.

58:32 Thus. So this is a pretty large composer. This is the project. Yeah. Just show the composer dot JSON. Line 28 down to a hundred And, of course, and, of course, all of these will have their own dependencies again too. Exactly. Yeah. A lot of Symphony stuff here, which is gonna have complicated dependency trees and doctrine as well, database stuff, I guess, is gonna rich. Okay. So No. This is a more typical thing that yeah. It takes ages with x with with xdebug enabled. So let's take a minute without xdebug. We're in for the long haul here. Right?

59:18 Yes. Take a time for people to get some questions and if there's anything they want us to cover over there. Or, alternatively, xdebug three that I'm working on will speed us up dramatically. But I wouldn't suggest we install that right now. So what's different than xdebug three that gives it the performance performance benefits? Because it is much more clever on when and what when and what it turns on. And there are some algorithms in there, especially that have to do with the stack that are a lot more are a lot better with allocating memory. So what xdebug two does for every time

59:59 a function is called, it creates this memory structure, which has the function name in it, where it is called from arguments, and so on and so on. And that structure is pretty big. At the end of the function, this memory is freed. When the next function is called, it's created again, and it is freed again. Now if you do this two times, that's fine. But typical bigger applications like Composer, this will happen hundreds of thousands of times. Now what xebit three does, it's instead of allocating and freeing it every time, it basically has a continuous set of memory allocated

1:00:39 Like a ring and will reuse it instead of freeing it. So it will detect when it doesn't have enough memory allocated and will allocate a chunk more, but it doesn't free it until the script ends. Ah, okay. So, potentially, it uses more memory, but it is significantly faster. Cool. Very cool. I'm waiting for people to expect xdebug three to be be stable, considerable, usable. Well, I use it all the time. I think it well, the test passed, so I guess that makes it stable. But I'd I would like to create, like, a a tech preview release

1:01:20 once I've made all the breaking changes in it because lots of names of settings change and things like that to make it easier to use and not having to remember all 70 different settings that we have. And yeah. So the idea is that there will at least be a release candidate when PHP eight comes out and hopefully a final release soon after that. But and that is November. That's that's how things stand now. But if you want to play with it, some GitHub should work. But please read the upgrade guide because things have changed. Definitely.

1:02:01 So does that clear question or was it a comment? It it's a comment to say thank you for xdebug three. Well, you are welcome. Yeah. You know, I think a lot of people get a lot of you know, xdebug is one of those tools that just becomes invaluable once you understand the basics and and how it works. Profile in general, you know, xdebug is a profiler for PHP. So Well, I think most people don't use it as a profile, but as it's as it's as a step debugger, but yeah. Yeah. I guess maybe it's it's just where

1:02:32 my head is at. You know? I I I I I see the value in profile, and I think it's invaluable for any code you have in production. You know, you need to know how it behaves in that environment and profiling it and and understanding it. Extract metrics from it, doesn't heat grass, flame grass, all these things. Like, there's just so much you can do with this stuff to really understand your application. Yeah. Then again, xdebug's profile is not meant to run-in a production environment because it's meant to run a development environment like we're doing now because it well,

1:03:05 I said has too much overhead or maybe had too much overhead because with xdebug tree, you would be able to selectively turn it on for just a single request. That's why I could do sampling in my production environment then. Yeah. Well, it's not quite that easy, but it as long as you don't enable any features, it doesn't slow anything down beyond, like, a few percent. But if you want to to do, like, real time application performance monitoring, which is basically what you're getting at the moment, xdebug is not made for that. Okay. It is it's

1:03:37 more more for developers trying to find performance bottlenecks in a normal situation and not depending on how your system is doing at the moment. Ah, okay. I understand. Robert's on a on a chat's having an interesting comment, and I agree with him. Which comment? Sorry. He says, can you run htop in the background so we see the numb the numbers jumping around and and not that composer's just frozen? Oh, so, apparently, you're getting comments much much faster than I am because it's only just popped in here now. So, yeah, can I run htop in the background so we can

1:04:17 play it? Yeah. Where I'm just following the YouTube stream on my other screen. So I see the the text the moment I type it. Yeah. I've got it coming through the the streaming software that we use. I think it's a little bit of latency, but hopefully not too bad. So and I bet you by the time I brew install htop, it's probably gonna finish up. Oh, yeah. I'll do my best. Come on, bro. Take that away. Know how to pronounce that surname. I mean, if you don't have htop, you can just try top instead. We'll get a nice color. So

1:05:07 That's true. Yeah. And I'll probably wanna run it on a full screen. It's pretty. Yeah. Sorted. So PHP uses 98% support line. Firefox uses a 30%, but oh, this probably because there's other video for you. Right? Yeah. Okay. That makes sense. I haven't looked at normal top for ages because I always use htop. Htop is taking its its sweet time. So oh, there we go. Let's drop out. There we go. It's much prettier, isn't it? It is. Yep. But yes. Can I filter an h shop? I'm not I'm not that familiar with visual. Can I filter yeah? Well,

1:05:59 f four. Yeah. I how do you type f four into terminal window? Yeah. Okay. And now we're just looking at PHP stuff, and we can see composer. It's quite good on the memory consumption. You know, we're setting a 2.5% there. The CP is is obviously doing a lot of computation there. Well, it would be nice if it could use all 16 of your course. I've heard a rumor that potentially, compulsive two has concurrency slash parallel support. Is that right? Okay. I don't I don't know, actually. Yeah. People are like I've done a couple of streams now on PHP technology. Mostly around containers.

1:06:38 And the last few times, people have been like, oh, you have to use composer too because it does all the downloading in parallel, which I'm assuming means that that spends up a thread per core and has them doing the dependencies. But it is the downloading of files. It's the IO, the disk IO, the network IO that is parallelized is not the solver. I don't think the set algorithm can be parallelized. Yeah. I don't think you'd be able to break that up. That would be very complicated. You'd like if private well, you just have to map register

1:07:06 solver. That would be crazy. Yeah. But because it's recursive, you can't, I think. Good point. Do you want to see how big the the cache client files get cutting? I don't think you want to. I'm not sure I do. Yeah. That's what I was gonna say. Why don't we run a watch? If you don't I don't have a watch. What kind of machine is this? Okay. It's yours. Oh, dear. Don't open the file in FIM. See, this is the thing. Right? Those files can get big. The thing is that q cache client actually sup supports g zed compressed files,

1:08:00 but xdebug doesn't do so yet. Actually, I don't think I have a ticket for that. Let me let me add check that. Let's see if it's still I mean, I'm assuming the reset that it's still CPU bound right now means that it's still on the software stage rather than the download stage. Yes. Absolutely. Considering it's not going to download any files because it's in your cache. Hoping so. But it should be in your cache because you ran it before. It's it's the 2.3 k, counting. CPU is still burned, running for ten minutes. Wow. Yeah. This takes ages. Right? I really I

1:09:00 Compiling Xdebug 3 for the performance gains!

1:09:02 really want to see how fast xdebug three is now. I think it'd be a good experiment. Oh, yeah. Definitely. We get to see the improvements there. I may do that in my my spare time this week. Just to absolute curiosity, man. I think it'd be faster to compile xdebug and run it again than waiting for this to get finished. I just yeah. I can go to xdebug. I mean, we've got time. Yep. We have, well, another twenty minutes. Yep. That was I wanted to search GitHub. What are you doing now? With the Chrome xdebug, but I'm sure the minute I get over

1:09:56 to my terminal now Just go finish. No. No. No. About finish. Just open another terminal. We'll be fine. Did it change things again? Yeah. Oh. There we go. That's an annoying bug. Okay. So clone xdebug. I need to is master okay? Do you want me to pull a branch down? Or No. It needs to be master. Alright. Can I just show I haven't I haven't gotten I can't see anything you typed on? Oh, that's very annoying. I can't keep switching back. There's no make fail. What's going on? I can't see what you're doing, so I

1:10:50 can't tell. Did you so what are the things that you're trying to type? Now you Let's stop the share again and I'll bring it back. It's just, obviously, some sort of glitchy bug happening. Okay. So it's here screen two. So I I cloned it and I typed make, but there's no make in process. Funny. There's this process for this. First thing to type is PHPIs. PHPIs? Oh, I I zed e. Yes. Yes. It should be with an s, but that's a recognize. That works? Dot slash configure. Robert, it's not a camera output that's lagging. It's

1:11:37 some graphics issue with sharing the screen. I am running the Pixar pair. So Okay. Yeah. Potentially, Harrison. Did that work? Yep. Yep. And now type make. No. You got a warning. Warnings are there to be ignored. It's true. For you. I need to fix them. It does sometimes different compilers will give different warnings. I can always ask at dash w all. Alright? That treats warnings. Is that hers, if I remember correctly? So the flags that I've set up for my own compile script does actually do that. It does w all and a whole bunch of other things. Okay. It works. Make install.

1:12:27 What about our running composer process? Is that are we You're not on Windows. This works. In Unix's, you can override files, and anything that's still memory works just fine. Can you type PHP minus v in? Sorry. You kinda dropped that there, minus. V for victory. Oh, shiny. Shiny indeed. Now do you want to go to your pseudo projects? Not shiny. C two has dropped or it had dropped drastically. I'm assuming this is about finished. I think it is zipping things. Yeah. Oh, it's it's showing showing you now. Yeah. Okay. Show the composer output on your terminal.

1:13:00 Profiling our complex composer configuration with much gains

1:13:18 Where did we go? It's in the top one. Okay. That should once this is done, we just run it again and see how much faster. This this took us what? Thirteen minutes? If I run htop again, it's been filter fourteen and a half minutes. Assuming it finishes in the next thirty seconds, fifteen minutes, it'll take. And our output down here is currently at 3.4 gig. There we go. Fifteen minutes. Yeah. It's done, though. Yep. K. So should I rename this file before we run it again? Yes. It's a big file. Hopefully, you have enough disk space.

1:14:13 It should be alright. So bar cam name, and I'll just actually bring it here. Oh, why am I crashing on the anyway, it doesn't matter. So we wanna run composer install again. Right? Yep. Same thing. Yeah. What sort of bit of walk fail? Well, why? Because the first time you run it, it already did all these things. Then we run it with x then we run it with compose with compose and not disabling xdebug. So it should be the same thing. It should be no difference. But the log files are now sorted. I does that not mean it doesn't run the

1:14:56 solver again? Sorry. What? Because the log files there, it won't run the solver again. Yeah. It's gonna use the log file. First the first profile that we made Composer disabled xdebug. Right? And then it ran. Then we used the environment variable to tell Composer not to disable xdebug, but we didn't remove any any log files. That was we the first time we ran it was on the simple example, though. This is the first time we've run Composer install on this proposal this directory. No. We've just run this. Oh. Oh, yes. You're right. You're right. Yes. Remove

1:15:41 the log file. You're absolutely right. Sorry. So Okay. So once one thing that you need to change, otherwise, it's unfair. Mhmm. See what it says, what the error message says. Has been renamed. Yes. So we need to change the setting in PHP I nine. So you want me to close this? Yeah. Abort this, remove the log file, and then we open PHP I nine. Remove the log file first before we forget. Okay. So I haven't finished resolving it, so we're okay. So now we wanna modify this. So instead of profile enable, it is xdebug dot mode.

1:16:31 You can just leave this in there. It doesn't matter. Equals profile. Yeah. You still got a warning, but yeah. It's a semicolon, not a hash. Actually, I don't know. I think And then I can just run to post install again? Yeah. Yes. Okay. Should we take a look at that other cache frame just now? Yeah. Let's do that. Well, this runs. Right. Let's stop that. There's no there's no log file here. And I'm just gonna run it with time. Let's get a a number from it so I don't need to run each top. Okay. Okay.

1:17:11 Here, cache grind and my local file here. It takes some time. It's a big fault. It needs to pass three dot three gigabytes of profiling information. Let's give it another minute. That grind will have would not have been able to handle this. The file is too big. Yeah. It really just takes as much time. There's no much you can do on this. I wonder what's gonna load first this this profile for xdebug three and compulsive. It's still loading it. It is. Oh, we have a progress part of here. Oh, yeah. It's about 30%, maybe maybe 25%.

1:18:21 Yeah. This is where the disc disc performance over Mac really sucks. Alright. No. It's the next time Derek is on the stream, bring my Linux laptop to the party. Mhmm. Much faster. I also believe that the error messages are causing a slowdown as well. And I Oh, yeah. I think that the next ebook three, I actually made sure that it doesn't show negative information in there so that will be faster on the site too. Just loading the phone. But I'm not a % certain. Profiler. I'm just creating a ticket for myself. So I don't forget that.

1:19:22 So dance? Yep. Yeah. I think it's only halfway through. Yeah. Ain't sure what to do about that. I wonder how many lines are in there. What does it show in the console output? It it tells you how many lines which line it is parsing. So the number in the middle, that's the line number. Yeah. That's a big line. 225,000,000. My computer is going haywire. It's you don't have enough memory, I think. I think that's your problem. It's starting to swap now. No. The file is only 3.3 gig, and I've got 32 gig around. Yeah. But how do you think what do

1:20:20 you think QCache Crime does for this? I assumed it was loading three gig into memory. Well, you have top find out. Okay. That was a mistake. Running w c was a mistake? Yeah. I'm only using half my memory. Yeah. But you also I have 1.3 gig as well. Yeah. That is not a lot of swap for that much memory. I normally have swap disabled. I've just not done it on a Mac. Not sure whether you can, actually. I mean, I've swapped disabled on my machine as well, but it has a bit more memory. Yeah. I'm not sure how big that fail

1:21:12 is. 4,000, 40 thousand, hundred thousand Half gigabytes. 27,000,000 lines. And it's about halfway done. But I think you run into swap here because it's not getting bigger. Oh. It's done. That's why. So, yeah, you can see now it's stuck on the on the software, and it now takes 90% of the time. Right? And you remember previously, it was 26%. Yep. But you can see how often things have been called. Yeah. That's 700,000 times. Thousand times. Interesting that this call is 700 I mean, that's only 4.77%, whereas the function call twice is 53. Yep. But look at call goes down here.

1:22:18 Yeah. Yeah. At the 1,400,000 and the 1 3 Yeah. And That is a lot of function calls. And this is where xdebug was actually terribly slow for doing that kind of stuff. I think it's done, by the way. Oh, okay. So can I close this one down? Is it is it done? Composer is installed, isn't it? It finished. It has. Yeah. It only took two hundred and fifty seconds this time. So six minutes instead of fifteen. Fifteen. Sorry. That's not true. It's four minutes, not six minutes. Yes. Four minutes. Okay. So while we shut this one,

1:22:59 there's not gonna be anything different between this queue cache going to the other one. Right? This the only difference there was that the xdebug was significantly faster. Exactly. Yeah. So that's what I've been spending my the last few months on making this go not suck too much. Because now I mean, four minutes is still not great, but it's not sixteen minutes or whatever or fifteen minutes. And I haven't even spent time optimizing composers specifically. So but yeah. Anyway, so if you would ask me how would I make xdebug go faster, I would do exactly the same thing.

1:23:36 I would use file grind, creating cache grind files and loading them into, you know, k cache grind in my case or q cache grind to analyze the profile and see where it's slow in the exact same way. And the process of identifying what is slow here is just following the percentages and the bigger lines and trying to find the functions where most of the time is being spent. Absolutely. Or what is often a good thing of doing it on the left hand side, you have the inclusive in self. If you click on the word self,

1:24:08 the things at the top are the functions that where most of the time is taken without it's calling all the functions. Okay. And so I just go down the list and see whether there's anything interesting in it. Okay. Oh, yeah. You just be sorting this list based on self and Yep. Looking for the functions for us by the most time. The first function I would look in in this case is the the one that is currently selected. It's called two times, but it takes up 11%. That is a lot. Unfortunately, your composer you don't have the source code locally.

1:24:46 So this was what showed me the code here. Yeah. So if I compiled composer, then I would have so I guess that's that's a important point here is if you're gonna profile you can't profile something distributed as a far a far. You would have to have that quote built. No. You can't you can't profile it, but you can't see the source code. K. Okay. Because QCache client or k crashing doesn't understand the file format. Right? And if we take a look at the, you know, the callers, we can see where that function is being called from. Do we

1:25:15 get any visibility beyond that, or is it is it just If you click on colors, you can see where this is called from, but you can also see that's in the graph already because the one that is selected is the red one in the middle. Okay. And if you can see what is if in the in the call graph here down here, you can see who who called it because it's the node above it. Ah, right. Gotcha. Okay. But you can see there's all the functions got two to 2,000,000 times down here. Yeah. Blue one. Oh, yeah. That's there we go.

1:25:51 Okay. Got it. So Is there any any difference that we would apply? Like, right now, I I feel like we're kind of identifying functions called based on their c p CPU performance. And is there anything different that has to happen if I wanna find bad actors with memory allocations? Yep. You see the worst time in your menu bar? Oh, yeah. Yeah. Ah. Change it to memory. So simple. It's the same idea. But then I have to make a big caveat here. There's that memory profiling is not nearly as accurate because, as I mentioned, it is impossible to see

1:26:32 the negative use of memory when things get freed. And, also, PHP's garbage collector can kick in at any time. Right. Sometimes you see memory being freed that isn't actually getting freed at the point where it says it is going to be freed because it's a garbage collect they're kicking in. Now with Composer specifically, that is not a problem because Composer disables PHP's garbage collector because it would make it two or three times as slow. And you don't really care in command line applications. Right? Yeah. Because, I guess, typically, they're not long running. They the the PHP will exit is,

1:27:19 I guess. Right. So anything where you you'd, like, run, like, a a PHP process that you want to run for hours, you want to have the garbage collector turned on. But if it's a one shot script, then you don't really care. That makes sense. And, yeah, you don't really want to wait for garbage being collected. Okay. Is there anything else you feel we should cover before we wrap this up? Because I feel like I don't think we have anything at the moment that I still can talk about. I mean, I would suggest you play around with your own PHP applications. I mean,

1:27:54 the people are listening. Oh, and your you, of course, as well. And, yeah, that's pretty much it. Alright. That was the same. That was awesome. That was really insightful again. I look at the head of this first. And it's just so much information. Like, it's a really cool tool that we have the ability to just inject like, I mean, installing xdebug and running that in their application was so trivial. That that was great. Yep. You turn it on. That that's pretty much it. And the speed performance of xdebug three was fantastic. So great job there. I think I

1:28:30 I didn't I knew you said it was faster. I wasn't expecting to go from fifteen minutes to sub four minutes. That's pretty impressive. Yeah. I wasn't expecting that either, to be fair. Surprised it wrote itself. Awesome. Alright, Chris. Sorry. I mean, I know with compose, it is the recursive calling that happens so often, and I know that was a contentious point. Yeah. Alright. Well, thank you very much for taking the time out of your day to join me and go through all this. This is really useful. I'm sure others are gonna find this fantastic as well. So thank you again,

1:29:06 Derek. I'll tweet out the link to the video once this, Rawkode. Alright. Perfect. Well, thank you again. I'll speak to you soon. Thank you for tuning in, and I'll see you all next time. Thanks. Bye.

Technologies featured

Meet the Cast

Weekly Cloud Native insights

Stay ahead in cloud native

Tutorials, deep dives, and curated events. No fluff.

Comments, transcript, and resources

More from Rawkode Live

View all 173 episodes
PHP

More about PHP

View all 7 videos