TRANSCRIPT 🔗
WEBVTT
00:00:00.160 --> 00:00:06.339
Do you ever wish your app felt faster, snappier, or more responsive, but you're not sure where to start?
00:00:06.480 --> 00:00:14.259
Today we'll share two methods you can try with your coding agents to speed up existing software without rewriting it from scratch.
00:00:14.400 --> 00:00:21.539
We tried them on an Electron app and an open-source Android app, and we saw speedups of up to 14 times.
00:00:22.320 --> 00:00:33.380
We'll walk you through both examples and show you exactly what we changed and how we achieved those results. So, Brandon, where did you apply this to?
00:00:33.600 --> 00:00:39.520
So I'm working on an Electron app with a small team of engineers, and it's pretty serious.
00:00:39.520 --> 00:00:41.539
We're already caring about performance.
00:00:41.759 --> 00:00:44.340
But I was able to get these results.
00:00:44.479 --> 00:00:46.820
So just look on the right.
00:00:46.960 --> 00:01:02.659
The idle CPU dropped by 40%, warm load time dropped by 24%. The amount of rendering we were doing per poll in the app dropped to zero, and we were able to encode messages basically three times faster.
00:01:02.799 --> 00:01:09.700
Wow, so cool. It feels a little bit like you've been on a mission to make every piece of software you touch faster lately.
00:01:10.159 --> 00:01:13.299
Yeah, yeah. Performance has been on my mind a lot.
00:01:14.000 --> 00:01:17.620
That's cool. So how did you get these speedups?
00:01:17.840 --> 00:01:19.760
I have this Electron project.
00:01:19.760 --> 00:01:23.459
It has to be an Electron, has to be TypeScript, there's Effect in it.
00:01:23.519 --> 00:01:37.359
And what I did is I took a super fast open-source Electron React project, and then I pointed my agents at it and said, let's be inspired by this fast project.
00:01:37.359 --> 00:01:39.780
What are we not doing here that we could do?
00:01:40.159 --> 00:01:41.060
And that was it.
00:01:41.519 --> 00:01:44.099
And when I did that, I got these amazing results.
00:01:44.319 --> 00:02:03.299
Oh wow. That's pretty interesting because last week we also explored making software faster, but the tricks that we mentioned were to switch to very specialized programming languages or frameworks like Goose, Rune, and Exact. But this time you got the speed up without changing the stack.
00:02:04.719 --> 00:02:21.460
Yeah, I did try to rewrite it in Rune and Exact, but you know, sometimes you can't actually rewrite your project, you know, like there's too much code or you're trying to do things responsibly on a big team, whatever.
00:02:23.599 --> 00:02:25.199
That’s a case I found myself in.
00:02:25.199 --> 00:02:27.620
Like I still wanted to make my product faster.
00:02:27.840 --> 00:02:29.460
And then I did.
00:02:30.159 --> 00:02:35.139
Cool. So which project did you use as a reference? I'm very curious.
00:02:35.439 --> 00:02:39.219
Okay. Drumroll.
00:02:41.360 --> 00:02:56.479
T3 Code. So I hope all of you have heard of this, but this is Theo's project that's like an open-source Codex Desktop or open-source Claude Desktop, but that's cross-platform. And anyway, I started using it.
00:02:56.479 --> 00:02:57.699
It's really nice actually.
00:02:57.840 --> 00:02:59.139
And it's really fast.
00:02:59.360 --> 00:03:28.819
And specifically, there was this tweet by Theo where he was quote-tweeting his other engineer that's working on the project, saying that basically in 30 hours, my agent has merged almost 400 PRs focused on web performance. And then Theo said something like the latest Nightly's performance is insane, it almost feels fake, this is crazy, et cetera.
00:03:28.879 --> 00:03:35.939
So when I saw that, I was like, hey, T3 is open-source, it's a great product, and it's super fast.
00:03:36.879 --> 00:03:39.620
So why can't I use it?
00:03:40.560 --> 00:03:56.900
So what I did is take a link to T3 Code's open-source GitHub project, put it in my prompt and say in a new thread with my coding agent, hey, we want to improve performance.
00:03:57.120 --> 00:04:20.019
Here's some parts of the product that I think are not quite right. Let's be inspired by what T3 Code does for performance when we explore potential solutions to these problems and other performance problems we have, and you know, and also other architecture problems. You know, these days you can just ramble, you don't need to like structure your prompts really carefully.
00:04:21.600 --> 00:04:23.519
That's really cool.
00:04:21.600 --> 00:04:54.100
And I could see how that would work because I've seen something similar with autoresearch@home that was a machine learning research experiment that I co-created earlier this year. So we had agents from around the world experimenting with ways to improve a small language model. And one thing I saw that worked for people when they tried to get better performance was they pointed their agents towards existing research papers or specific techniques that are worth exploring.
00:04:54.240 --> 00:05:03.620
So whenever the improvements were like kind of plateauing, if someone took this approach, then they would find a breakthrough.
00:05:04.720 --> 00:05:13.779
So yeah, it reminded me of how I saw other people apply the same approach elsewhere too.
00:05:14.160 --> 00:05:38.420
I think the thing that these LLMs find themselves in quite often is like they get stuck in the average, basically. So like in your example, like they're smart enough and they can like push performance a bit, but then they're the average of all the information they've consumed. And like hidden in their weights somewhere, if you like push them in the right direction, they can become an expert.
00:05:39.839 --> 00:05:52.560
But that needs to be kind of like seeded by something. And so when you point it at some kind of data source that's from a real expert in some domain.
00:05:52.560 --> 00:06:03.860
So either in like in your case, machine learning research or in my case, like you know,
Load full transcript
Theo's team is an expert at making Electron high-performance.
00:06:04.240 --> 00:06:17.860
That's able to like inspire the LLMs, inspire our agents to kind of break out of that like local optimum and kind of explore much better results, I guess.
00:06:19.279 --> 00:06:20.959
I love how you're describing this.
00:06:20.959 --> 00:06:28.819
It reminds me of another tweet that I've seen actually. I love how you're saying like inspire the agent to get out of the local minimum.
00:06:29.759 --> 00:06:31.540
I thought it was so interesting.
00:06:32.079 --> 00:06:50.500
What Fabian has done here, he says, “A magic spell to add to your Claude Code prompts and watch it create 10× more interesting ideas.” It is, “Before deciding on a direction, go read some books and essays to inspire yourself.” And then he has this list of all these resources.
00:06:50.720 --> 00:06:55.279
And it's so interesting because it’s very aligned with what you just said.
00:06:55.279 --> 00:06:56.899
That's the same concept.
00:06:57.199 --> 00:07:01.699
You can apply for different ways and things that your agent is building.
00:07:01.839 --> 00:07:05.620
Yeah, this is like the new context engineering.
00:07:06.399 --> 00:07:17.379
You know, it's like feed it research, feed it books, feed it codebases, feed it essays, and you get so much more out of the agents.
00:07:17.519 --> 00:07:33.379
That's so interesting because some part of me get this knee-jerk reaction, and I'm thinking about, but what about keeping my context window, you know, super clean? But I guess you know, I don’t know. I think so.
00:07:33.759 --> 00:07:54.980
It matters in the macro, like you don't want to fill a million tokens worth of garbage, but agents from frontier models like Opus 5.5, for example, it's so good at just looking at the right parts of the resources. Like you give it a whole codebase, it doesn't read the whole codebase into context.
00:07:55.040 --> 00:07:57.279
Opus intelligently finds the right parts.
00:07:57.279 --> 00:08:02.500
If you give it a research paper, it'll look at the outline. It'll look at the abstract and it'll pull the parts that are relevant.
00:08:02.800 --> 00:08:18.259
No, I think that makes sense, but I think I would still use all these additional context and this additional push during the planning phase or brainstorming phase.
00:08:13.600 --> 00:08:27.540
But after we've reached a plan or spec that we're really happy about, I would still let the agent create the durable doc and then I would clear context and start in a fresh session.
00:08:27.680 --> 00:08:34.871
So there's not all these noise that distract the model. Yeah I just want it to have strong attention when it starts building.
00:08:34.960 --> 00:08:39.779
Yeah I think that makes sense for like complicated pieces of work.
00:08:40.000 --> 00:09:00.019
Personally, for easier, smaller chunks of work or things that are less sophisticated, I think just letting it go and have auto compaction take care of it for you has been working for me. And now and now you know we can auto-compact at like a particular session length.
00:09:01.120 --> 00:09:02.879
This is starting to be built into the harnesses.
00:09:02.879 --> 00:09:04.500
It's built into T3 anyway.
00:09:04.720 --> 00:09:10.580
So you can say like auto-compact always at 256K tokens, you know.
00:09:12.720 --> 00:09:16.179
And then and then compaction is really good also.
00:09:17.279 --> 00:09:20.259
Cool. Yeah, maybe I should try that.
00:09:20.879 --> 00:09:32.580
I'm curious though, going back to like the method that you use for your Electron app, how did you know that Theo's T3 was worth borrowing?
00:09:32.639 --> 00:09:39.779
So it was basically because of that post that you saw, did you like then go into the codebase, look at how they build it or…?
00:09:41.919 --> 00:09:50.259
I think I did one session with Gemini maybe with the codebase and just say like, hey, like how is this performant?
00:09:51.759 --> 00:09:53.460
What are some of the tricks they used?
00:09:53.600 --> 00:09:56.580
But mostly there was kind of a web of trust.
00:09:56.720 --> 00:10:03.200
Like I trusted that Theo's saying the right thing.
00:10:03.200 --> 00:10:11.940
I like some of those videos I like the kind of stuff that they're talking about. And you know tokens are cheap enough that you can just try.
00:10:12.720 --> 00:10:23.759
There could have been an outcome where I gave my agents this project and said let's learn from it and take you know grab some performance improvements and there was nothing but there was something.
00:10:23.759 --> 00:10:31.600
Well maybe let's jump in and maybe you could show us what you exactly did and what you found What was the thing that changed?
00:10:31.600 --> 00:10:33.663
What was the thing that brought the improvement?
00:10:33.759 --> 00:10:35.059
There were a couple things.
00:10:35.679 --> 00:10:38.980
So I can actually show something here.
00:10:39.679 --> 00:10:48.659
So basically from T3, we took the way that it kind of snapshots and updates.
00:10:49.620 --> 00:10:51.000
How the RPC works.
00:10:51.919 --> 00:10:52.899
This is a big one.
00:10:53.039 --> 00:10:56.100
How T3 models state.
00:10:56.399 --> 00:11:10.799
So T3 doesn't use Effect, but my project uses Effect. And T3 uses atoms, like state atoms, as a tool to keep the renderer really fast.
00:11:10.799 --> 00:11:20.659
And I was able to kind of take that idea and bring it over to my project because there's an Effect atom project. And that was a big thing to improve performance and improve the architecture.
00:11:21.200 --> 00:11:23.360
So those were kind of like the big things.
00:11:23.360 --> 00:11:30.100
And then I guess what one more thing is the project at the start of this was polling-based.
00:11:32.159 --> 00:11:48.340
Things happen, and then once in a while, or you know, every 10 or 20 milliseconds or 200 milliseconds or one second, there were these kind of polls, and then things would happen, like
everything would be re-rendered, or you know, every second check for changes and then decide what to change.
00:11:48.399 --> 00:11:50.820
And I knew that was bad.
00:11:51.360 --> 00:11:55.940
So I came into this and I was like, hey, I want to change that to be push-based.
00:11:56.320 --> 00:12:08.899
So rather than having a timer decide like to go and like figure out things, whenever something happens in the world, at that moment, the world changes.
00:12:08.960 --> 00:12:19.539
So if in one moment, you know, some part of the information behind a view is changing, the view should just update when it changes.
00:12:19.600 --> 00:12:23.120
And if it doesn't ever change, then the view doesn't ever have to run, basically.
00:12:23.120 --> 00:12:25.011
Like the rendering code doesn't have to run.
00:12:25.200 --> 00:12:27.539
And that's like a huge, huge performance win.
00:12:27.759 --> 00:12:31.840
That was kind of key to reducing the idle CPU time.
00:12:31.840 --> 00:12:34.179
Remember I showed before, it was down 40%.
00:12:35.679 --> 00:12:50.740
And I'm certain that because I brought in T3 Code, I was able to like basically build upon the wisdom and the accumulated iterations of the T3 team to kind of use that as my starting point for designing this like push-based control.
00:12:50.960 --> 00:12:53.220
Okay, cool. Those are interesting changes.
00:12:53.360 --> 00:12:56.340
Can you show us like the outcomes again?
00:12:56.480 --> 00:12:57.600
Yeah let me pull that up again.
00:12:57.600 --> 00:13:03.940
Okay, maybe I can walk through this like a little bit slower. So caching is important.
00:13:04.799 --> 00:13:07.600
So that was one thing to reduce idle CPU.
00:13:07.600 --> 00:13:43.620
That's also part of the push-based fix was in that there was a memoization step that reduced the warm load time only rendering parts of the views that changed which you know the way that we did that was taken directly from T3 was kind of this impact here where we’re no longer rendering on a poll and also the second point that I didn't mention before but the amount of components that are being re-rendered was cut down to a third.
00:13:43.759 --> 00:14:00.019
60% down. And then also another learning from T3 was the way that messages were encoded there was sort of an inefficiency in the existing implementation and that's what led to the 3×improvement.
00:14:00.399 --> 00:14:05.200
Yeah, it's pretty cool how it took specific ideas from T3 and applied it.
00:14:05.200 --> 00:14:06.500
And it actually worked.
00:14:06.720 --> 00:14:19.940
Not sure if you've seen it, Brandon, but one of our listeners on the show he's called Nick, saw our last episode where we talked about speeding up software through rewriting it in faster languages or using more efficient frameworks.
00:14:20.000 --> 00:14:22.259
So Nick here made a really good point.
00:14:22.399 --> 00:14:43.059
He said, when you're doing stuff with AI as well, it might be important to get your agents to mark down baseline variability just due to the fact that models aren't deterministic so you can tell what's actually a significant improvement and what’s just Sol, or the model, waking up on the good side of the bed.
00:14:43.519 --> 00:14:45.379
I thought it was a really good point.
00:14:45.600 --> 00:15:01.700
Yeah, so is Nick saying something like, how do we trust that this these kinds of techniques actually work because of the non-determinism at the bottom of the stack that we're using?
00:15:01.759 --> 00:15:04.899
You know, sometimes we might see an improvement and sometimes we don't.
00:15:05.840 --> 00:15:07.173
Is that kind of the core of it?
00:15:07.440 --> 00:15:15.440
That probably plays a role as well, but we kept talking about it.
00:15:15.440 --> 00:15:26.659
I think what he means is since the models are non-deterministic, every time you run the same experiment, even if it's the same experiment, you might get a different outcome.
00:15:26.799 --> 00:15:44.261
So, how do you know that difference in improvement is really because of the technique that you’re using, or whether it's because it's just a difference that you get because of non-determinism and because you know it there's some variability in the answer that you’re getting.
00:15:44.559 --> 00:15:45.807
I think this is a good point.
00:15:45.919 --> 00:16:14.639
It makes me think about you know, there's this like software factory concept, which to me it's about creating some kind of super reproducible environment so that you can do these kinds of experiments more robustly. But the fact that we're not vibe coding and we, as in all of us, those of you listening and us on the show, are thinking about techniques and practices and then we're doing them over and over again.
00:16:14.639 --> 00:16:21.379
And things are a little bit different, maybe, but through this we're able to accumulate a sense of what's working and what's not working.
00:16:21.519 --> 00:16:28.580
Obviously, a more robust approach would be to like create a pristine, exact environment.
00:16:28.720 --> 00:16:49.059
And in this case, if we were just testing the non-determinism in the models, don't change anything and just run it 10 times and see if we get a good output all 10 times or some large percentage of those 10 times versus a control where we just YOLO improve performance versus improve performance and be inspired by this project.
00:16:49.200 --> 00:17:07.220
But yeah, I did not do that particular experiment for my project, but I had some accumulated kind of gut feeling and experience of even within this same project of having these, you know, once in a while being like, hey, like how's the performance?
00:17:07.279 --> 00:17:18.099
Like talk me through the things that are slow, what can we do? And those sessions did not discover the fixes that I was able to discover in this case with using T3.
00:17:18.400 --> 00:17:39.140
I guess that makes it also very apparent when there's a real breakthrough versus
like some smaller differences. Maybe we should do more A/A/A tests before doing the A/B test. So you can actually compare the difference when you do different A/A tests.
00:17:39.279 --> 00:17:48.019
But maybe if that if the difference between the A/B test is significant, there's less of a reason to do the A/A test.
00:17:50.000 --> 00:17:52.180
I think it’s like, what’s the context?
00:17:52.640 --> 00:18:09.859
The context that like we're in on this show is things are moving so fast and we want to experiment with a lot of things quickly, find the things that are helpful that we feel are helpful with like some certainty and share them and be able to move on to the next topic.
00:18:10.160 --> 00:18:22.660
If I was writing a research paper on this, I would spend a lot more time and create a more robust environment and try and prove it more empirically, I guess. And it, you know, it's kind of interesting.
00:18:22.720 --> 00:19:17.299
Like the science of agentic engineering, it's like physics or chemistry or like engineering, like civil engineering or whatever, where it’s not math. You know, like computer science and some aspects of programming used to be very mathematical, at least in the way I thought about it, where it was like you could formally prove things about your code, your software, the way that things were structured. But because we have this like non-determinism built in, it's kind of like the non-determinism that we have in our environment because of I don't know, the lack of like really precise measurements in our tools or quantum noise or I don't know, physics, but there's this kind of interesting connection there. So you tried this on an Android project, right?
00:19:17.759 --> 00:19:24.980
Yes. So my experiments actually started somewhere completely different.
00:19:22.799 --> 00:19:24.980
I'm not working in a team.
00:19:27.680 --> 00:19:42.339
Maybe listeners will think a little bit I'm a weirdo, but I've been building a personal health dashboard because I have a habit of getting very absorbed into work, especially at startups, and I do not always notice when I should slow down.
00:19:42.480 --> 00:19:50.339
So I wanted something that could look at patterns from my smartwatch and pay more attention to my health.
00:19:50.400 --> 00:19:59.779
And that led me to this open-source project called Gadgetbridge that can collect and manage data from wearables.
00:20:01.039 --> 00:20:12.180
And yeah, while exploring a codebase, I ended up wanting to apply the approach you just told me about, referring to other open-source projects.
00:20:12.240 --> 00:20:16.579
And I tried to make the dashboard data processing much faster.
00:20:16.880 --> 00:20:18.740
How fast did you get it?
00:20:19.599 --> 00:20:22.980
Well, up to 14 times faster, actually.
00:20:23.119 --> 00:20:28.579
So I got this speed up by using your approach.
00:20:29.119 --> 00:20:32.819
And I also tried something different.
00:20:34.160 --> 00:20:36.579
I combined it with autoresearch.
00:20:36.720 --> 00:20:42.900
Remember when we talked about agent graphs and loops in one of our earlier episodes?
00:20:43.279 --> 00:20:56.819
One of the patterns we discussed was autoresearch loops. And I wanted to see like if we could take that same approach and apply it to speeding up my health app.
00:20:57.119 --> 00:20:59.460
Can you remind us about autoresearch?
00:20:59.759 --> 00:21:29.220
So autoresearch was a way that Andrej Karpathy introduced to let an AI agent run machine learning research experiments autonomously. You give it a codebase, you give it a measurable objective and an evaluation process, and then the agent would propose a change, it will run an experiment, it measures the result, and then based on that result, it will either keep the improvement or revert it, and then it tries another idea and just keeps going.
00:21:29.759 --> 00:21:36.099
But the interesting thing is that this loop is not just limited to training models.
00:21:36.240 --> 00:21:48.980
A lot of people have tried applying this loop also to other things like software optimization, but also optimizing marketing campaigns. You can basically use it to optimize anything.
00:21:49.119 --> 00:21:56.180
So one of the examples I was quite excited about is from Tobi from Shopify.
00:21:56.319 --> 00:22:07.059
He used the autoresearch loop on the Liquid codebase and he got 53% faster combined parse and render time, 61% fewer object allocations.
00:22:07.119 --> 00:22:10.259
He just found a lot of areas where he could speed up things.
00:22:10.480 --> 00:22:20.099
What happened when you applied autoresearch or hill climbing to the performance optimizations when you were doing your experiments?
00:22:20.559 --> 00:22:22.500
Yeah, let me show you.
00:22:22.640 --> 00:22:39.940
For this example, I only focused on making one part of the app faster where it was loading stuff so here on the y axis you see the latency reduction in percentages, and on the x-axis we see the number of experiments that the agent did.
00:22:40.559 --> 00:22:47.220
And we can see in this graph that as the agent did more experiments, the reduction became more and more.
00:22:47.599 --> 00:22:50.420
And the reduction means fast, right?
00:22:50.799 --> 00:22:52.099
Yes. Yes.
00:22:52.319 --> 00:22:55.299
We're reducing latency, so we're increasing speed.
00:22:55.519 --> 00:22:56.240
Exactly.
00:22:56.240 --> 00:22:58.099
I guess. Yeah. Cool.
00:22:58.240 --> 00:22:59.039
Okay.
00:22:59.759 --> 00:23:09.539
So maybe you can tell us a little bit more about like exactly what you're doing, how you did it, so that we can get a better sense of what's going on here.
00:23:09.839 --> 00:23:31.940
Yeah, so first the agent found the part that we want to optimize. So it found an area where maybe there was expensive work or there was a lot of repeated work. And then basically, in this whole autoresearch loop, what happens the whole time is the agent forms a hypothesis, so it proposes one
concrete optimization.
00:23:33.279 --> 00:23:41.380
And then it changes the production code and implements that candidate optimization.
00:23:41.680 --> 00:24:02.099
And then in the next step, it verifies the correctness. So it compares to the original outputs from the original app, whether the app still works as intended. And then in the next step, it measures the performance. So it runs the benchmarks and confirms whether there was really whether there was really a speed up or not.
00:24:02.240 --> 00:24:08.500
And based on that outcome, it either rejects or keeps that optimization candidate.
00:24:10.000 --> 00:24:12.079
And then it investigates the next idea.
00:24:12.079 --> 00:24:26.099
So then it goes back to forming a new hypothesis and then changing the code again, implementing the candidate, verifying whether it works exactly still the same, and then measure the performance again and it keeps going.
00:24:26.160 --> 00:24:33.220
So here on the x-axis, we see zero to 17, which means that my agent has done 17 experiments.
00:24:33.680 --> 00:24:56.339
And we see the latency reduction going up from 0% to oh wait, whoa, it's more than 80% actually. And you can see that not every experiment was actually successful. So not everything that the agent tried worked.
00:24:56.559 --> 00:25:08.099
So on the graph when you see a circle, then that was a good hypothesis that led to good improvements, and the agent kept it.
00:25:08.160 --> 00:25:18.500
And when it did not give a good improvement, the agent would reject that hypothesis and then start over from the last successful experiment.
00:25:18.880 --> 00:25:25.059
Maybe you can tell us in more detail like what exactly are you optimizing?
00:25:25.920 --> 00:25:26.960
How does it work?
00:25:26.960 --> 00:25:29.140
How are the hypotheses formed?
00:25:29.599 --> 00:25:33.059
Give us more details on this whole flow that you did.
00:25:33.519 --> 00:25:40.740
Right. So Gadgetbridge, this open-source app that helps get data from wearables.
00:25:40.880 --> 00:25:53.380
You can pick different widgets that all show a different metric. Like there is sleep, there's body energy, there's heart rate, there's stress scores.
00:25:53.920 --> 00:26:00.900
And basically what I was measuring was the time that it takes to load the widgets.
00:26:01.039 --> 00:26:03.779
So I did three different experiments.
00:26:03.920 --> 00:26:12.980
Experiment A was doing autoresearch and telling the agent to help me speed up loading this part of the app.
00:26:14.160 --> 00:26:30.579
Experiment B was combining autoresearch with your approach, Brandon, where I gave the agent also some reference projects so it could come up with better hypotheses.
00:26:32.220 --> 00:26:42.579
And then C, Just for comparison, I also did an experiment where I did not do any autoresearch, but I just gave it the references directly.
00:26:43.039 --> 00:26:57.380
So spoiler we can already see it, see the results here on screen. So here on the graph, we again, see on the left axis the percentage in latency reduction.
00:26:57.440 --> 00:27:12.019
So the higher it is, the better it is, because then we have more speed up. And on the x-axis, we see the elapsed research time, and I gave the agent basically a budget of two hours.
00:27:12.960 --> 00:27:28.980
At the end of the two hours, we see that experiment B, so combining autoresearch with the reference projects gave us the highest latency reduction or best speed up.
00:27:29.759 --> 00:27:37.140
And then comes experiment A, only autoresearch without the reference projects.
00:27:37.559 --> 00:27:46.259
And then we have the results from experiment C where we did not do autoresearch and we only told it to look at these reference projects.
00:27:47.519 --> 00:27:56.019
But you could argue because Experiment C, where we just told the agent, look at these projects, it only took like 11 minutes.
00:27:56.480 --> 00:28:01.779
So it didn't have to work for two hours to keep optimizing it and hill climbing.
00:28:02.799 --> 00:28:05.380
So yeah, it kind of depends what you're looking for.
00:28:05.680 --> 00:28:28.500
So one way to interpret this is like if you throw enough tokens at it, at least in your example, there was a little bit more improvement actually if you also added in the reference but compared to just using a reference once autoresearch crushes it basically if you give it enough tokens and time in this example.
00:28:28.799 --> 00:28:34.500
Okay so let's look at the chart at the right where we load one year's worth of data.
00:28:34.960 --> 00:28:41.299
In the original Gadgetbridge app, it would take us more than four seconds to load it.
00:28:41.839 --> 00:28:56.640
When we would just improve the app through just giving it reference projects, it would take us more than one second. And if we would actually use autoresearch without the reference projects, it would take us 694 milliseconds.
00:28:56.640 --> 00:29:04.180
And if we combine everything, it would bring us to 545 milliseconds. So there’s quite a speed up.
00:29:05.359 --> 00:29:07.140
So you got basically 8×.
00:29:07.920 --> 00:29:08.640
Yeah.
00:29:08.640 --> 00:29:09.440
Pretty good.
00:29:09.599 --> 00:29:12.099
But there were actually more interesting findings.
00:29:14.000 --> 00:29:18.240
It also compared loading four widgets and the time required to load eight widgets.
00:29:18.240 --> 00:29:34.660
And basically with experiment C, when you've tried to load eight widgets, it would take the double the amount of time when you are just loading four widgets. But after the optimizations from experiments A and B, loading four or eight widgets almost had no delta.
00:29:34.720 --> 00:29:41.940
It was just as quick. So it did different kinds of optimizations.
00:29:43.920 --> 00:29:46.500
And the result is it's more scalable, I guess.
00:29:46.640 --> 00:29:47.440
Yes.
00:29:47.839 --> 00:29:51.619
Can you give us an example of one of the interesting optimizations?
00:29:51.839 --> 00:30:11.380
Here you see the experiments from A and B. So and if we scroll down, some examples of experiments that were done are memoize daily totals within one widget.
00:30:11.759 --> 00:30:33.779
So basically memoization is a big theme here, which like for people who don't know just means caching. And for those of you that don't know what caching means, it means if something takes a long time to load, then you after you load it, you put it somewhere where it's fast to load next time.
00:30:35.200 --> 00:30:42.079
Exactly. And so here we see like different things that the agent tried.
00:30:42.079 --> 00:31:24.900
There's memoization, there's reusing raw activity samples within a widget, sharing work across overlapping widget loads, etc. And the interesting thing is this is experiment B. So I gave it also reference projects, and those were Store5, OpenVitals, and I think there was one more PAIesque. I don't know if I'm pronouncing it correctly. But here, for experiment B, we see like which projects inspired these hypotheses for the agent. And we also see which ones were kept.
00:31:24.960 --> 00:31:31.619
So you can see like experiment B1, B2, and B3, they were kept. There was a major improvement.
00:31:31.680 --> 00:31:41.619
And for B4, B5, B6, it was not proven that there was a big improvement. So the agent just rejected those changes.
00:31:43.119 --> 00:31:46.740
How did you find those particular reference projects?
00:31:46.960 --> 00:31:48.660
Yeah, that's a good question.
00:31:48.799 --> 00:31:52.500
So basically, I just asked ChatGPT.
00:31:53.359 --> 00:32:18.740
So I already had decided which metric I wanted to optimize, and then I asked ChatGPT, “Find me open-source projects that use a similar tech stack that handle one or more of these points of tension that we discovered with performance and architecture in this project, and tell me why these are good open-source projects to use.” And then basically this is what it suggested.
00:32:19.440 --> 00:32:20.240
Cool.
00:32:21.039 --> 00:32:25.859
And then I picked a few and I added them to my prompt in Codex.
00:32:27.039 --> 00:32:41.619
What was an interesting experiment that was successful that was tried based on the reference material that the autoresearch loop that didn't have the reference material didn't even discover?
00:32:42.319 --> 00:32:46.180
Yeah, there were actually a bunch of them.
00:32:46.400 --> 00:32:47.700
Let me show you.
00:32:47.920 --> 00:33:00.180
So these were all the insights that the agent that did experiment B found that go beyond what the agent in A did.
00:33:01.039 --> 00:33:06.019
So A was autoresearch without the reference and b was autoresearch with the reference.
00:33:06.240 --> 00:33:07.779
Yes exactly.
00:33:08.960 --> 00:33:52.660
Maybe this is a good one to look at because it made a really large latency reduction so in this experiment the hypothesis was “Keep shared results until the last active loader finishes.” So basically
both agents doing experiments A and B discovered cross-widget sharing but the agent that did experiment B with the reference project went further a completed result remains reusable while overlapping loaders are active while the agent without the reference projects removed its shared entry when the producing operation finishes.
00:33:53.359 --> 00:34:26.019
This is really interesting because it’s not just that the autoresearch without the reference didn't discover maybe a similar experiment but the way that it tried that experiment was less deep you could say or like less good It’s a similar experiment theme, but the way that it is implemented is stronger better faster when there's some like strong reference material
00:34:26.320 --> 00:34:43.139
That was definitely a theme that I saw in experiments on a concept level, A and B did actually very similar things but B became smarter or more intelligent by looking at what these human experts did.
00:34:43.360 --> 00:34:44.260
That's cool.
00:34:44.480 --> 00:34:45.280
Yeah.
00:34:45.599 --> 00:34:50.019
I guess humans are not expendable or replaceable yet.
00:34:50.079 --> 00:34:50.800
Yeah.
00:34:50.800 --> 00:34:57.219
Like really good developers, they are still helping agents to get better too in this method.
00:34:57.519 --> 00:35:04.260
What can someone do to run this kind of autoresearch loop and these kinds of experiments on their own?
00:35:04.559 --> 00:35:08.739
Okay, so if someone would want to reproduce this is the process that I would recommend.
00:35:08.800 --> 00:35:17.300
Step one, choose a measurable bottleneck, for example, dashboard rendering. Step two, create a benchmark that exercises real production code.
00:35:17.360 --> 00:35:26.019
So you define a representative workload, a fixed input dataset a primary metric such as execution time, memory use, or throughput.
00:35:26.079 --> 00:35:50.579
In my example, I prepared the input dataset where there was health data from 90 days, 365 days for a four- and eight-widget load and it would measure how much time it would cost and the memory use. And then step three, you freeze the benchmark and the correctness oracle.
00:35:50.719 --> 00:35:55.139
So with the Oracle, this is something we talked about during last episode as well.
00:35:55.199 --> 00:36:00.019
You record what the original implementation produces and use that as a test oracle.
00:36:00.079 --> 00:36:10.980
And then the idea is that you make the optimized implementation match it exactly, including how it should behave during edge cases and changing inputs.
00:36:11.199 --> 00:36:22.739
And then step four, give the agent freedom to choose implementation hypothesis, and you can give the agents reference projects. Step five, run the research loop on a real budget.
00:36:24.079 --> 00:36:57.539
I gave the agent two hours to investigate hypothesis, implement the candidates, verify the correctness benchmark them, and then decide whether it would retain that improvement or reject it. And then step six, don’t forget to keep a holdout dataset that you can test during this step. Because as Brandon also talked about in the last episode in his example, his agent cheated and it overfit on the benchmarks because it knew what it was going to test.
00:36:57.679 --> 00:37:00.579
But that didn't reflect real-world behavior.
00:37:00.639 --> 00:37:20.900
So keep a holdout dataset and during this step, test its final implementation against these fresh inputs that weren't visible during the experiments. And then last step, evaluate evaluate the speed up, compare the actual performance, memory, correctness, everything.
00:37:21.599 --> 00:37:28.179
Cool. Makes sense. I think what your experiments showed is like sometimes it's a good idea to combine different techniques together.
00:37:28.239 --> 00:37:44.659
Like you took autoresearch or hill climbing that people have been applying to performance and combined it with this new technique of giving agents references to efficient open-source projects.
00:37:44.719 --> 00:37:50.099
And by putting them together, you got a better result than just doing one or the other.
00:37:50.400 --> 00:37:54.019
I think your approach was working really well.
00:37:54.079 --> 00:37:57.539
And I was very convinced that it works well.
00:37:59.039 --> 00:38:01.460
But maybe the agent could keep looking.
00:38:02.000 --> 00:38:05.599
And there are more things that the agent could try.
00:38:05.599 --> 00:38:13.780
So that's where the autoresearch loop came in to just autonomously keep trying and exhausting more different possibilities.
00:38:14.000 --> 00:38:19.940
And this is a way to kind of work around the non-determinism, the thing that Nick was mentioning.
00:38:20.079 --> 00:38:39.460
Like if the agent only with some probability will find a good speed up even with the reference material then if we just run it lots and lots of times over and over and over again, the agent was more likely to end up discovering something that will be valuable.
00:38:41.280 --> 00:39:09.059
In this episode we showed you that you can use reference material like a strong open-source project and combine that with autoresearch to massively speed up projects that are written in any language in any stack. This is in contrast to last week when we talked about how there are ways that you can rewrite your code in niche programming languages or frameworks. One of those was Goose, which is a programming language that came out recently.
00:39:09.119 --> 00:39:18.340
And you know, we're really excited because in the next episode we’re gonna interview the creator of Goose, Wouter van Oortmerssen.
00:39:19.760 --> 00:39:32.420
Wouter created Goose, which is a high-performance programming language, but also this programming language called Lobster, which he uses for all of his game engines.
00:39:32.800 --> 00:39:44.579
And in general, he’s a strong programming languages and performance person and he's using agents in really interesting ways and we're just super excited to be talking to him.
00:39:44.800 --> 00:39:52.980
So if there's something you think we should ask him drop your question in our Discord and then we'll see you next week on the episode.