AI 智能体如何在你睡觉时工作:Lauren Tan 与 Roshan Sadanani 谈 Grok Bot 与 Grok 4.6

How AI Agents Work While You Sleep: Lauren Tan & Roshan Sadanani on Grok Bot and Grok 4.6

罗山·萨达纳尼 Roshan Sadanani · MTS · 2026-08-13 · 约 56 分钟 · 原视频 ↗

打开互动全文版(中英对照 + 朗读 + 问答)→

本期速览 · Overview

来自 Cursor 的 Lauren Tan 与 Roshan Sadanani 做客 MTS,现场演示 Grok Bot,讲解拥有独立电脑的持久化智能体如何在你睡觉时自动完成任务,并探讨 Grok 4.6 带来的能力变化。

Lauren Tan and Roshan Sadanani from Cursor join MTS to demo Grok Bot, explain how persistent agents with their own computers automate tasks while you sleep, and discuss what Grok 4.6 changes.

要点 · TL;DR

核心观点 · Key points

反共识 · Contrarian takes

本期章节 · Chapters(共 17)

全文 · Full transcript(中英对照)

介绍与Grok Bot演示 Introduction and Grok Bot Demo

Host

我经常谈到我构建的这个叫 Benny 的机器人。我想弄清楚如何让我的智能体在我睡觉时自动为我修复 bug。所以这就是我们早期实验的灵感来源,比如如果每个人都能定义自己的机器人,给它一个身份,并赋予它自己的电脑以及例程和自动化。所以我现在有机器人,每当有人给我们关于 Grok Bot 的反馈时,我的机器人就会自动去修复它们,我只需要审查它们的代码。大家好,欢迎回来。今天我的嘉宾是来自 Cursor 的 Lauren Tan 和 Roshan Sadanani。今天早些时候,Cursor 和 SpaceX 联合发布了 Grok 4.6。非常兴奋能与你们谈论这个新模型,并做一些 Grok Bot 的现场演示。Lauren、Roshan,欢迎来到 MTS。

I talk a lot about this bot that I built called Benny. And I wanted to figure out how would I make it so my agents could just automatically fix bugs for me while I sleep. And so that was the inspiration for some of our earlier experiments like you know what if everybody could define one of their own bots, you know, give it an identity and give it things like its own computer plus routines and automations. So like I have like bots right now that are you know every time someone gives us feedback on Grok Bot my bots are automatically going off and fixing them for me and I just like review their code. Hello everyone and welcome back. Today I'm joined by Lauren Tan and Roshan Sadanani from Cursor. And earlier today cursor and SpaceX jointly announced Grok 4.6. So excited to talk to you both about the new model and also to do some live demos of Grok Bot. Um Lauren Roshan, welcome to MTS.

Lauren

非常感谢邀请我们。

Thanks so much for having us.

Roshan

是的,非常兴奋。

Yeah, really excited.

Lauren

太兴奋了。

So excited.

Host

我知道你们在直播前刚告诉我,我们实际上要做一场 Grok Bot 的现场演示。所以在我们直接进入演示之前,能否分享一下 Grok Bot 是什么,以及 Grok 4.6 可能如何改变它的能力?

I know you just informed me right before we went live that we're actually going to do a live Grok Bot demo. So before we just jump into that, can you share with me about what Grok Bot is and how does Grok 4.6 maybe change what it's capable of?

Lauren

是的,我们对 Grok Bot 非常兴奋。昨天收到了大量好评,所以过去一段时间我们一直在努力将它上线。希望人们有机会尝试,如果你还没有,现在就可以注册试用。动机真的是让与智能体交互和使用智能体变得更容易。当我们在内部开始构建这个产品时,它获得了大量的内部 PMF。从市场团队到运营团队、工程团队、产品团队,每个人都紧紧抓住它,并找到了使用智能体的有趣方式,我认为这对他们的工作很有意义。

Yeah, we're super excited about Grok Bot. Tons of really great reception yesterday and so it's been sort of a labor of love to bring it live over the last little while. Hopefully folks have had a chance to try it out and you have if you haven't yet you can go sign up for and try it out right now. Really just motivated by making it easier to interact with and use agents. This product got a ton of internal PMF when we started building it internally. Everyone from go to market teams to ops teams to engineering teams to product teams just like latched on to it and just really found fun ways to use agents that I think make a lot of sense for their jobs.

Host

太酷了。你们直接是怎么使用它的?你说你们团队找到了内部 PMF。那个具体时刻是什么?有没有发生什么例子?

That's so cool. How have you guys been using it directly? You said you found internal PMF with your team. What was that specific moment? Was there an example that happened?

Roshan

是的,我认为早期有一个非常小的团队在原型设计和构建 Grok Bot。它开始非常有机,就像他们只是自己使用 Grok Bot,但开始与几个人分享,然后我开始使用它,我用它预订了 Odyssey IMAX 的电影票。

Yeah, I think so early on there was a very small team prototyping and building Grok Bot. And it started out very organically like you know it was just them using Grok Bot for themselves but they started sharing it with a few people and it started you know like I started to use it I used it to book the Odyssey IMAX tickets

Host

70 在哇哦我的天哪,那是一个里程碑,一个新的基准,能够在那里买到票。

70 in wow oh my gosh that is that is a milestone a new benchmark was able to get tickets there

Roshan

但是是的,能够使用智能体来自动化许多你可能不一定会想到的事情,这真的非常令人兴奋。而且 Grok Bot 有自己的电脑,所以它超级强大。即使你不在电脑前,它也能运行。所以,它一直很棒。

but yeah it really was very exciting to be able to use agents to you I know automate like so many different things that you might not necessarily really think you can. And Grok Bot has its own computer, so it's like super powerful. It runs even if you're not at your computer. So, it's been it's been awesome.

Host

我有点好奇。它在内部是如何运作的?所以,内部同事只是测试不同的东西,然后那些开始起飞的东西,我们就会想,好的,我们如何把它变成商业产品?

I'm a little curious. How does it work internally? So, do internal teammates just test out different things and then ones that are starting to take off, we're like, okay, how do we make this into a commercial product?

Lauren

是的,我认为大致就是这样运作的。我们认为我们的同事在使用产品以及使用智能体产品方面品味很高。因此,对于我们构建的许多东西,我们会在内部发布,并从每天使用它们的公司其他人那里获得反馈,寻找内部 PMF。通常,这对于向更广泛的世界发布一些东西是一个好迹象。所以 Grok Bot 遵循了完全相同的流程。不过,我认为 Grok Bot 真正独特的地方在于,就像我之前说的,无论角色如何,从运营到市场到插入你的角色,有人找到了 Grok Bot 的用例,很大程度上是因为它与您已经使用的所有工具无缝对话,然后显然就像 Lauren 说的,它有自己的电脑,所以它是一种持久性智能体,与之交互感觉非常新颖,所以我认为其中一些交互,希望我们稍后能展示给你看,非常非常酷。

Yeah, I think that's like roughly how it works. We think that our colleagues are pretty high taste when it comes to using products and also just like using agent products. And so for a lot of things we build we sort of ship them internally and get feedback from the other folks at the company who are using them daily look for that internal PMF. And usually that's been a good sign for kind of releasing something into the broader world. And so Grok Bot kind of followed that exact same process. What was really unique about Grok Bot though I think is that kind of what I was saying earlier sort of regardless of role everywhere from like ops to go to market to insert your role here. Someone found a use case for Grok Bot and a lot of that's because it just talks so seamlessly with all the tools you already use and then obviously like Lauren was saying it has its own computer so it's sort of this persistent agent that sort of felt really novel to interact with and so I think some of those interactions which we'll hopefully show you in just a second are really really cool.

Host

好的,让我们开始吧。我觉得我已经得到了所有预览。我准备好进入演示了。让我们开始吧。

All right let's jump in. I feel like I got all of the preview. I'm ready to jump into the demo. Let's take it away.

Lauren

是的。我可以开始,也许我们可以稍微来回一下。所以你现在看到的是 Grok Bot,这是我的一队机器人。我这里有一个协调智能体,他是我的参谋长,了解我的日历,并且可以给我的其他智能体发消息,所以可以检查其他智能体的进展。所以这是我的协调智能体在给 shopppee 发消息,shopppee 帮助我在网上买东西,并了解我最近的购买。

Yeah. I can start maybe we can go back and forth a little bit. So what you're looking at here is Grok Bot and this is my team of bots that we're looking at. I have a coordinator agent here who's my chief of staff and knows stuff about my calendar and can actually message my other agents so can check in on the other agents and how they're going. So here's my coordinate agent messaging shopppee who helps me buy stuff on the internet and learning about the recent purchases I just made

Host

比如 Odyssey 的电影票。

like Odyssey tickets.

Lauren

完全正确。是的,比如 Odyssey 的电影票或者是的。我的杂货可能。那是我们在内部看到的一个非常有趣的用例。但然后你知道这些智能体也有自己的电脑,并且可以登录你使用的所有工具。所以,就在这之前,我刚设置了一个营销智能体,它可以访问我的 LinkedIn。所以,如果我点击这里的按钮,我们可以看到这个营销智能体有自己的屏幕。它登录了我的 LinkedIn。实际上只是通过浏览 Chrome 拉取一些我的 LinkedIn 帖子。所以我会继续让他为我更新 LinkedIn。我们看看能不能做到。我们想发布我们正在谈论 Crockpot Live。实际上。别忘了标记正确的 MTS 账户。

Totally. Yeah, like Odyssey tickets or Yeah. My groceries maybe. That was a use case we saw internally that was really fun. But then you know these agents also have their own computer and can be signed in to all the tools you use. And so, right before this, I just set up a marketing agent who has access to my LinkedIn. And so, if I hit this button here, we can see that this marketing agent has its own screen. It's logged into my LinkedIn. And actually just pull some of my LinkedIn post just by browsing on Chrome. So I'll just go ahead and ask him to update LinkedIn for me. We'll see if we can do this. We want to post that we're talking about Crockpot Live. actually. Um, don't forget to tag the right MTS account

Host

或者 MTS live。

or MTS live.

Lauren

MTS live。嗯,这些智能体真正酷的地方在于,你可以像与同事聊天一样与它们聊天。这是设计灵感的重要部分,就是让它感觉像一个非常聪明的同事在聊天中陪伴你。而不是需要等待轮到你,或者等待一些思考发生之类的。所以,嗯,是的,他将开始工作,并尝试从我的 LinkedIn 发布。所以我们稍后会检查他的进展。嗯,我们看到的另一个很酷的事情是整理演示文稿或帮助自动化工作中许多更繁琐的事情。所以我们内部有一个叫 Grok Bot wins 的频道。所以我要请这里的这个智能体,我的参谋长,整理一些来自那个频道的反馈,也许实际上用 Figma 幻灯片来做,这样我们可以分享出去。所以是的,让那些人忙一会儿。嗯,哦,看起来我们的帖子可能要上线了。你可以看到哦,那超级快。

MTS live. Um, and what's really cool about these agents is you can just chat with them like you're chatting with a colleague. And that was a real huge part of the design inspiration here is just making it so that this feels like you have a really intelligent colleague that's hanging out with you in the chat. Um, versus having to like wait your turn maybe or wait for some thinking to happen or or whatever else. So, um, yeah, he's going to start working and and trying to post from my LinkedIn. So we we'll check in on him on in a second. Um the other cool thing that we've seen a lot of cool use cases with is putting together sort of presentations or helping automate a lot of the more drudgery that might happen in your job. Um so we have a channel internally called Grok Bot wins. And so I'm going to ask this agent here, my chief of staff to put together uh some feedback from that channel uh and maybe actually uh do it in Figma slides so we can maybe share those out. So yeah, let those guys cook for a little bit. Um oh, and it looks like our post might be going live. You can see Oh, that's super fast.

Host

那真的很酷。我希望它能让任何人都能看到。看起来它确实会这样做。

That is really cool. I hope it makes it available to anyone. It looks like it is going to do that.

Lauren

哦我的天哪。

Oh my gosh.

发布招待会 Launch reception

Host

你们昨天才正式发布。反响怎么样?Lauren,想先听听你的看法。

You guys announced this all yesterday. What was the reception like? Maybe Lauren would love to get your opinion here.

Lauren

嗯,我觉得反响非常正面。大家真的很喜欢 Grok Bot 的形象、动画和 logo,特别有意思。更不用说 Grok Bot 的各种使用场景了。

Yeah, I think the reception has been super positive. People really love the Grok Bot identity, the animation, the logo. It's really fun. And not to mention all the use cases where you can use Grok Bot.

Lauren

我们听到很多反馈说它非常直观,看起来就像 iMessage。我看到有几个人把 Grok Bot 分享给他们的妈妈,然后妈妈也开始上手用 Grok Bot 了。所以 Grok Bot 这么受欢迎,我真的很惊讶。

I think we've heard a lot of cases where it's very intuitive. It looks like iMessage. I've seen a couple people share Grok Bot with their mom, and their mom's onboarding onto Grok Bot. So I've been really blown away by how well received Grok Bot is.

Lauren

当然还有很多要做的地方,对吧?我们还有一些零星的 bug 要修。但总体而言非常正面,也很高兴我们终于把它发布出来了。

There's still a lot more to do, right? We have a few bugs here and there that we have to fix. But overall, it's been very positive. And very excited that we finally got to launch it.

Grok 4.6与模型进展 Grok 4.6 and model progress

Host

你们今天还发布了另一个东西。把这两者放在一起,现在能实现什么?

And you announced another announcement today. So pairing those two together, what is now possible?

Roshan

Grok 4.6 非常强大。在同样的 token 成本下,它比 4.5 聪明得多。所以我觉得对于编程任务和我做的那类工作——因为我做很多工程方面的工作——我大量使用 Grok 4.6,它能力强太多了,而且真的非常快。

So Grok 4.6 is really powerful. It's much more intelligent than 4.5 at the same token cost. So I think for coding tasks and the type of work that I do, because I do a lot of engineering work, I use Grok 4.6 a lot for that, and it's just way more capable. It's really, really fast.

Roshan

我也还在用其他模型,比如 Fable 和 Saul,但 Grok 就是快,对吧?而且价格实惠,很便宜。所以我真的很喜欢用它。

I still use the other models too, like Fable and Saul, but Grok is just so fast, right? And it's affordable. It's cheap. So I really like using it.

Lauren

是的。我觉得我们和 SpaceX AI 团队一起发布 Grok 4.5 时聊到的一点,就是我们要训练的模型不只是为了写代码。而随着 Grok 4.6 以及我们在 Grok Bot 上的一些投入,我们不断看到,有了这些非常出色的模型,能做的事情多得多。

Yeah. I think one thing that we talked about when we launched Grok 4.5 with the SpaceX AI team was this idea that we're going to train models for more than just code. And I think what we're continuing to see with Grok 4.6 and some of the investments in Grok Bot is that there's a lot more that's possible with these really great models.

Lauren

所以,我们很期待模型持续进步,期待参与前沿模型的讨论,也期待把这些带到现实世界里。

And so, yeah, we're just excited for the models to keep improving, to be part of the discussion on the frontier of models, and to be able to bring that into the world.

设计Grok Bot Designing Grok Bot

Host

是的,我对你们展示的东西非常兴奋,因为我知道 Cursor 最初主要是在智能体式编程领域起家的。我之前也说过,Cursor 其实是我开始使用 vibe coding 工具的大门。它是我用的第一个真正的工具。我用 Cursor 的模型,然后一路升级,直到今天还在用。

Yeah, I'm really excited about what you show here, because I know that Cursor started off mainly in the agentic coding space. I was sharing earlier that Cursor is actually my gateway into starting to use vibe coding tools in general. It was the first actual tool I used. I used the Cursor models and then I just kept updating from there, and I still to this day use it.

Host

后来我意识到——其实在我测试 Grok Bot 之前——我就想,哦,你可以用同一个工具做研究、做别的事情。而且即便大家说智能体在扩展、在增长,它主要还是编程智能体,因为用智能体做日常事务的实际基础设施和用户体验实在太差了。

And then I realized, before I was actually testing out Grok Bot, I was like, oh, you can use this same tool to do research, to do other things. And still, even though people say agents are expanding and growing there, it's still mainly coding agents, because the actual infrastructure, the UX to use agents for everyday things sucks.

Host

我觉得 OpenClaw 可能是第一个走向大众的,但就像你说的,我不觉得我妈会用 OpenClaw。就连我自己,也在 Telegram 里搭了一整套 OpenClaw。在我的界面里看起来有点像这样,我有我的购物智能体之类的,但它老是出问题,我总在修它。这个太棒了,我很喜欢整个 UI 和结构。你们是怎么——创建这个、创建 Grok Bot 的设计过程是怎样的?

I think OpenClaw was maybe the first mainstream, but like you mentioned, I don't think my mom would ever be using OpenClaw. And even myself, I set up a whole OpenClaw in a Telegram. It looks kind of like this in my UI, and I have my shopping agent, all that stuff, and it breaks all the time and I'm always trying to fix it. This is awesome and I love the whole UI and structure. How did you—what was the design process going through creating this, creating Grok Bot?

Roshan

嗯,其实需求很简单,就是保持简洁。说得俏皮一点,我觉得这真的很实在。很多 AI 应用给了你很多控制和能力,但有时候这种能力是和复杂性相平衡的。所以我们这里的设计需求就是:首先,怎么把它做得非常简单?所以消息式的界面多少是从这里得到启发的。当然,还有我们后来陆续加的一些设计细节。

Yeah, I mean, the brief was basically keep it simple. If I can be a little cheeky, I think that's actually really real. A lot of AI applications have a lot of control and power that they give you, but sometimes that power is balanced with complexity. And so really our design brief here was, how can we make this really simple first and foremost? And so that's kind of where the messaging interface became a little bit inspired from. And then of course some of the design touches that we added over time.

Roshan

Lauren,你算是把它整个做出来的人,不知道你有没有要补充的?

I don't know, Lauren, if you'd add anything, kind of having built it all.

Lauren

我不敢说我把它全做出来了,但我觉得团队确实在追求一个非常干净、简洁的用户界面,因为如果你用过 Cursor,你大概是个资深开发者、资深用户。它非常——有很多开关和花哨的功能,非常针对编程场景定制。

I wouldn't say I built it all, but I think the team really strove for a very clean, simple user interface, because if you've used Cursor, you're probably a power developer, a power user. It's very—there's a lot of knobs and whistles, and it's very tailored, focused for coding.

Lauren

而做 Grok 时,我们真的很想换一个全新的视角:如果你的智能体更像一个同事,会是什么样子?对吧?你不一定想事无巨细地管着一个同事,问他“你现在在调用什么工具?”而是想把它当人一样对话。

And with Grok, we really wanted to take a fresh perspective on what would it look like if your agent was really more like a colleague, right? You don't necessarily want to micromanage a colleague and say, what tool calls are you using right now? But you want to talk to it like a person.

Lauren

对。你想看到他们在电脑上做什么。所以,我们尽量让界面保持优雅和简洁。

Right. You want to see what they're doing on their computer. But yeah, so we've tried to keep the interface really elegant and simple.

Grok Bot适用人群 Who Grok Bot is for

Host

太酷了。我很高兴能同时采访你们两位,因为我们有产品侧,也有软件工程侧。幕后还有一整个团队,这里面有很多工作。

Really cool. I love that I have both of you on the interview, because we have the product side, we have the software engineering side. There's a whole team behind the scenes, too. There's a lot of work on this.

Host

等等,除了你们两位,还有更多人在做这个?

Wait, there's more people besides just you two on it?

Roshan

那当然。

No, for sure.

Host

所以有你们两位在场,就能非常全面地了解创建 Grok Bot、把这个产品推向大众究竟需要什么。我知道它的用户可能和典型的 Cursor 用户有点不同。你们设想中,Grok Bot 的主流用户会是谁?

And so, having you both here, you get a really comprehensive overview of what it actually takes to create Grok Bot and get this product into the mainstream. I do know the user might be a little bit different from the typical Cursor user. Who are you envisioning are going to be the mainstream adopters of Grok Bot?

Roshan

嗯,我们真的觉得这对每个人都有用。就像我们刚才说的,我们在内部看到这个发布时,我觉得外面有很多工作都亟待变得更高效。

Yeah, I think we really see this being useful for everyone. So kind of like what we were saying, when we saw this launch internally, I think there's a lot of work out there that's just rife to be made more efficient.

Roshan

我们内部做这个的动机,其实是看到 Cursor 内部有一群人自己在搭智能体,把聊天拼起来,做 Slack 机器人。其实 Lauren 有一个非常有名的 Slack 机器人,现在还活在我们的 Slack 里。而把它搭起来需要大量上下文。

And I think the motivation for why we built this internally is we actually saw a bunch of folks within Cursor who were building their own agents, kind of constructing the chats together, building Slack bots. Actually, Lauren had a really famous Slack bot that still lives in our Slack instance. And it takes a lot of context to put together.

Roshan

所以想法就是:我们能不能把它打包起来?这些机器人是给前置部署工程、软件工程和我们的运营团队用的,我们就是想,能不能用一种非常有趣的方式把它产品化?就是这样。

And so the idea was, well, could we package that up? And these bots were for forward deployed engineering and for software engineering, for our ops teams, and really just wanting to say, could we productize that in a really fun way? So yeah.

Lauren

是的。我经常聊我搭的这个叫 Benny 的机器人。他就像一只小狗,那是他的头像。

Yeah. So yeah, I talk a lot about this bot that I've built called Benny. He's like this little dog. That's his avatar.

构建机器人修复bug Building bots to fix bugs

Roshan

但我和 Benny 的想法其实是——你知道,我是个挺懒的人,我想搞清楚怎么——当时 Cursor 收到了太多 bug 报告,我就想把它们全修了。

But the idea I had with Benny was really—you know, I'm a fairly lazy person, and I wanted to figure out how—we were getting so many bug reports for Cursor, and I wanted to just fix them all.

Host

嗯。

Yeah.

Roshan

于是我开始琢磨,怎么让我的智能体在我睡觉时自动帮我修 bug。

And so I started thinking about how I would make it so my agents can just automatically fix bugs for me while I sleep.

Roshan

这就是我们早期实验的灵感来源,我们想做一个更持久的机器人。我觉得我们从那里借鉴了一些想法,因为很多人问我:你是怎么建的?我怎么能建自己的?这启发了 Grok Bot 背后的一些思考——如果每个人都能定义自己的机器人,给它一个身份,给它自己的电脑、例行程序和自动化,会怎样?所以我现在有生活机器人,每当有人给 Grok Bot 反馈,我的机器人就会自动去修,我只需要审查它们的代码。

And so that was the inspiration for some of our earlier experiments with building a more persistent bot. And so I think there were some ideas that we took from there because I got so many questions like how did you build—how can I build my own? I think that inspired some of the thinking behind Grok Bot—like, what if everybody could define one of their own bots, give it an identity, and give it things like its own computer plus routines and automations? So like I have life bots right now that are—every time someone gives us feedback on Grok Bot, my bots are automatically going off and fixing them for me, and I just review their code.

Host

那你现在的工作变了吗?

So what's your job now changed?

Roshan

确实变得有意思了。我几乎成了我数字员工的经理——是的。挺有意思的。

It's definitely become interesting. It's like I'm almost like a manager for my digital—yeah. So it's pretty interesting.

Lauren

其实很了不起的是,Grok Bot 本身有很大一部分也是用 Grok Bot 建的。我觉得这就像一个非常酷的反馈循环,这些智能体能自我分诊问题。它们能写代码,所以能连接云智能体。劳伦,我不知道你有没有那个演示,我们想展示的。

It's actually remarkable how much of Grok Bot was built with Grok Bot too. I think that's like a—it's been a really cool feedback loop where these agents can self-triage issues. They can write code, and so they can connect to cloud agents. And I don't know if you have a demo of that, Lauren, that we wanted to show.

Lauren

是的,我有。

Yeah, I do.

Host

哦,我喜欢这些演示。太好玩了。

Oo, I love these demos. This is so fun.

Lauren

这是为了让它有互动性。

This is to make it interactive.

Host

没错。你解释一些东西,然后你会说:“哇,我确实有个演示打开了。让我现在给你看看它实际怎么运作。”

Exactly. You explain something and you're like, "Wow, I do have a demo pulled up. Let me just show you now how it actually works."

Host

我们将继续关注,就在我们的赞助商信息之后。11labs,能在每个渠道和模态上以人类水平沟通的 AI。11labs.io/mts。在 Neon 上扩展你的初创公司。数百万开发者和初创公司已经选择 Neon 作为他们的后端。从免费计划开始,或在 neon.com/mts 为你的初创公司获得高达 10 万美元的信用额度。特别感谢我们的赞助商 Kong,AI 连接平台。以严格的安全和治理连接 API、LLM、智能体和系统。konghq.com。

We'll continue monitoring right after this message from our sponsors. 11labs, AI that communicates at human level across every channel and modality. 11labs.io/mts. Scale your startup on Neon. Millions of developers and startups have already chosen Neon for their backend. Start on the free plan or get up to $100,000 in credits for your startup at neon.com/mts. Special thanks to our sponsor Kong, the AI connectivity platform. Connect APIs, LLMs, agents, and systems with serious security and governance. konghq.com.

Lauren

是的。所以我之前已经问了我的幕僚长,今天有没有看到什么有趣的 bug。它找到了几个。你也可以看到,我在机器人的电脑上打开了 X,以防万一。但是的,你知道,我可以让它派发任务。所以我这里有一个沙团队——抱歉,一个 Grok Bot 团队。他们每个人负责不同的功能。现在我的幕僚长要把这些任务发给那些智能体。过一会儿我们会看到它发给不同团队成员的一堆消息。然后它们会去实际处理那些任务。最后我会收到一个可以审查的拉取请求。我会收到视频,所以我会收到截图。嗯,是的。所以这里还有一个例子,这是我工程团队的一个智能体。我觉得这几乎是一个不太明显的功能,但如果你在 Cursor 上设置了云智能体,你的 Grok Bot 机器人实际上可以启动它们。

Yeah. So I kind of asked my chief of staff already like if there's any interesting bugs that we saw today. And it's found a few. You can also see I have X open on my bot's computer just in case. But yeah, you know, I can tell it to dispatch. So like I have a sand team over here—or sorry, a Grok Bot team. So each of them kind of are responsible for a different feature. And so now my chief of staff is going to send off those tasks to those agents. And in a minute we'll see a bunch of messages that it'll send to my different team members. And then they'll go off and actually work on those tasks. And then at the end of it I'll get like a pull request that I can review. I'll get videos. So I get a screenshot. Um and yeah. So like here's another example where this is like one of my engineering team agents. And I think this is like almost like a feature that's not super obvious but if you set up cloud agents on Cursor, your Grok Bot bots can actually kick them off.

Lauren

所以就像这里,你知道,我们有一个——我有一个云智能体,它用自己的电脑运行,而这个智能体在管理它。所以它已经有一堆任务在进行中,我稍后有一堆 PR 要审查。

So like here, you know, we have—like I have a cloud agent that's running with its own computer that this agent is managing. And so it's got like a bunch of things in flight already, so I have a bunch of PRs to review later.

Roshan

我觉得这里也展现了软件开发未来的一个非常令人兴奋的方向:你实际上是在与一群执行特定任务的智能体交谈和协作,然后你退后一步,成为它们的管理者。感觉那个愿景在这里以一种非常有趣的方式成真了。所以是的。

I think there's something really exciting about the future of software development here too, where it's really like talking to and working with a bunch of agents that are doing specific tasks, and then you kind of just step back and become the manager of them. And it sort of feels like that vision is coming true in a really fun way here. So yeah.

Host

太棒了。我看到这里有一堆猫的照片。

That's amazing. And I see here it's a bunch of cat photos.

Lauren

哦,是的。

Oh yeah.

Host

所以你的所有智能体都是真正的猫。

So all your agents are actual cats.

Lauren

是的,我就是喜欢猫。所以我决定给它们一些傻傻的头像。只是为了给我的 Grok Bot 一点个性化。默认的 Grok Bot 头像也超级可爱。我是在我们添加那些之前加的。但就是图个乐子,你知道。

Yeah, I just love cats. So I decided to give them silly profile pictures. Just to personalize my Grok Bot a little bit. The default Grok Bot avatars are super cute as well. And I added these before we added those. But it's just having a bit of fun, you know.

Host

是的,Roshan,你暗示了一个趋势,这当然是智能体编程未来正在发生的,而 Cursor 一直处于见证这一切发生的前沿和中心。越来越多的代码被自动化,由这些智能体完成,所以作为人类,你成了这些智能体的木偶师,它们为你处理所有这些任务。我知道那是你特别兴奋的世界。你能多分享一点为什么你对此感到兴奋吗?这在人类层面上实际解锁了什么,主流观众可能没有意识到?

Yeah, Roshan, you hinted towards something that is a trend that of course is happening with the future of agent coding, and Cursor has been at the front and center of seeing all of this happen. More and more code is getting automated and is done by these agents, and so as a human you become this puppeteer of agents who are handling all these tasks for you. I know that's a world that you're particularly excited about. Can you share a little bit more why are you excited about that? What does that actually unlock at maybe the human level that people in the mainstream audience might not realize?

Roshan

是的,完全同意。我觉得如果用一个词概括,那就是效率。不管什么角色,人们脑子里都有很多想法——比如我有很多产品想法想构建到 Cursor 里。而限制因素就是——从想法到存在的流程中总会有瓶颈。所以我认为,能够向这些问题投入大量智能体,然后让它们产出真正高质量、并且符合我自己会放入产品中的品味的东西——那就是愿景,对吧?就像那个梦想。就是从思想到存在。所以对我来说,要努力的方向就是——我们能不能以这样的方式构建这些东西:无论是我管理一堆智能体,还是让智能体管理其他智能体,或者与 Lauren 的智能体合作,或者不管是什么形式——我们都能真正地缩短、压缩、再压缩那个周期,越来越短。而且我认为如果你看看 Cursor 作为一家公司的演变,那就是我们在很多方面朝着那个未来构建自己的方式——通过不断引入越来越多的智能体工具和复杂性。所以是的,我认为那就是愿景,我们对此感到兴奋。

Yeah, totally. I think if I had to pick one word, it would be efficiency. I think there's so many ideas in people's heads regardless of role—again, like I have so many product ideas I want to build into Cursor. And it's the limiting factor—like there's always some bottleneck in that idea-to-existence pipeline. And so I think the promise of being able to throw fleets of agents at these problems and then have them produce things that are really high quality and sort of align with the taste that I would myself put into our product—that's the vision, right? Like that's sort of the dream. It's like being able to go from thought to existence. So to me that's the thing to work towards—is can we build these things in a way where whether I'm managing a bunch of agents or asking agents to manage other agents or working with Lauren's agents or whatever that looks like—we're able to really shorten, compress, compress, compress that cycle more and more. And I think if you look at the evolution of Cursor as a company, that's sort of how we've built ourselves towards that future in a lot of ways—by continuing to introduce more and more agent tools and complexity there. So yeah, I think that's the vision and we're excited for it.

工程角色的演变 Evolution of Engineering Roles

Host

那么软件工程团队发生了怎样的变化?从你开始在 Cursor 工作到现在,有什么不同?

And then how has it changed on the software engineering team? What differences from when you started working at Cursor to how it is now?

Roshan

我认为在智能体世界里,工程师的角色演变就像我提到的,你有点像你智能体的工程经理。但我觉得现在作为工程师,我们很大一部分责任也是保持代码库处于一种状态,让产品经理和设计师也能贡献高质量的代码。这也是我在 Twitter 上经常谈到的,就是投资于重构、重写,甚至重写你的代码库,这样即使智能体有时不那么聪明,它们也能真正茁壮成长。比如把你的规则和风格指南编码成实际的 lint 规则或硬性约束,让 CI 失败。所以再次强调,我认为最大的突破是,作为工程师,我可以赋能很多其他人去做他们以前做不到的事情,同时我也能做以前做不到的事情。因为我在 Cursor 做了很多大型重构和迁移,我 mostly 都是自己做的,还有一个猫智能体。

I think the way I see engineers' roles evolve in the agent world is, like I mentioned, you're sort of like an engineering manager for your agents. But I think a big part of our responsibility now as engineers is also to keep the codebase in a condition where product managers and designers can contribute high-quality code. That's something I talk a lot about on Twitter as well, which is investing in refactoring, rewriting, even rewriting your codebase so that agents can really thrive even if they're not very smart sometimes. Things like encoding your rules and your style guides into actual lint rules or hard constraints that fail CI. So again, I think the big unlock is that as an engineer I can empower so many other people to do things that they couldn't do before, and I can do things that I couldn't do before as well. Because I've done a lot of big refactors and migrations at Cursor and I did them mostly by myself with one other cat agent.

Roshan

是的,所有的猫智能体都疯狂运行,我转换了一大堆东西,这本来会花费我或一个工程师团队几个月甚至几年的时间来完成。

Yeah, all the cat agents were just going wild and I converted a bunch of stuff which would have taken me or a team of engineers months or even years to finish.

Host

哇,太不可思议了。从外行人的角度来看,你可能会想,好吧,既然智能体能做所有这些编码,软件工程师的角色是什么?但如果你实际看看地面上发生的事情,对更多这类工程师的需求比以往任何时候都大。这可能朝着你暗示的方向发展,现在你可以构建软件,从想法到执行的时间线变得如此压缩。我们现在有了像 Grok Bot 这样的东西,它最初是你们在构建的,然后你可以用 Grok Bot 来构建 Grok Bot 并将其投入商业生产。这也是你看到的趋势吗,越来越普遍?

Wow, that's incredible. And as an outsider's perspective, you might think, okay, now that agents can do all this coding, what's the role of a software engineer? And if you actually look at what's happening on the ground, there's more demand than ever for more and more of these engineers. And it's probably towards something that you hinted now that you can build software with the thought to execution timeline is getting so condensed. We just now get something like Grok Bot that started off as that's something you guys are building and then you could use Grok Bot to now build Grok Bot and put it out into commercial production. Is that also what you're seeing just as a trend happen more and more?

Lauren

是的,我认为原型想法的时间大大缩短了,所以测试东西非常快。我认为我们能够——就像 Grok Bot 背后的团队能够以令人难以置信的速度前进,只是因为这些工具变得更好。显然,模型变得更好是其中很大的一部分。所以,是的,我认为就 Grok Bot 而言,动机真的是围绕如何让这个产品对人们越来越有帮助。至于趋势,我认为这会变得更容易。我认为人们在其中仍然扮演着非常重要的角色,对吧?无论是品味论证还是其他类似的组合。但是的,我认为想法比比皆是,看到越来越多的想法成为现实将令人兴奋。

Yeah, I mean I think the time to prototype ideas has gone down a bunch and so it's really quick to test things. I think we've been able, like the team behind Grok Bot has been able to move incredibly quickly just because of these tools getting better. And obviously the models getting better is a huge component of that. And so, yeah, I think that like to bring it to the Grok Bot side of things, the motivation there is really around how can we make this product more and more helpful for folks. As far as the trend, I think this is going to get easier. I think there's still a really strong role for people to play in all that too, right? Whether it's the taste argument or some other combination like that. But yeah, I think it's just ideas are abound and it's just going to be exciting to see more and more of them come to reality.

Roshan

哇,是的,我个人非常喜欢的一个类比或隐喻是这个想法——我喜欢食物。我是个大美食家。我有点把我的智能体想象成一个厨房,我称之为米其林厨房。所以也许我的角色有点变化,也许我不再自己烹饪所有的食物。但我有一队机器人和智能体,我有点像雇佣了他们,对吧?我通过技能或重构训练他们以我会做的方式写出好代码。所以我的角色变得更像主厨,对吧?我可能组装一盘食物。我负责质量控制。但如果你投入很多拥有一个真正有能力的智能体团队,你可以做更多的事情。现在想想,你团队中的每个工程师都可以拥有这样一个团队在他们背后,你真的可以解决更多问题。你知道,你可以构建更多功能。不是所有功能都应该构建,但你有更高的生产力和速度。

Wow, that's yeah, the sort of analogy or metaphor that I personally like a lot is this idea that—so I like food. I'm a big lover of food. And I kind of think of my agents as sort of like a kitchen, a Michelin kitchen is what I call it. And so maybe my role has sort of changed in that maybe I'm not cooking all the food myself anymore. But I have a team of bots and agents that I've sort of hired, right? And I've trained through skills or refactoring to do good code the way that I would have done it. And so my role is becoming more like a head chef, right? Like I maybe assemble a plate of food. I own the quality control. But if you invest a lot in having a really capable team of agents, you can just do so much more. And now think about that with every engineer in your team can have one of these teams behind them, you can really solve a lot more problems. You know, you can build more features. Not all of them should be built, but you have much more productivity and velocity.

Host

是的,我确实喜欢你暗示的内部文化,你实际构建东西,测试它,而且 Cursor 的员工本身对其他工程师、其他产品人员、我想其他消费者一般会希望看到什么存在有一定的品味。你有没有什么提示可以分享——好吧,如果你没有的话——关于可能即将出现的东西,甚至人们内部正在做的事情?

Yeah, I do like what you hinted about the internal culture of you actually build things, you test it out and that the employees themselves at Cursor have a certain taste for what other engineers, what other product people would, other consumers I guess in general would want to see exist. Do you have any hints that you can maybe share—okay if you don't—but of what might be coming up or even something that people are working on internally?

Lauren

是的,我们肯定想使 Grok Bot 更好。我们昨天作为测试版发布了这个,所以收到了大量各种形式的反馈。我们的目标只是让这些助手、这些机器人尽可能有帮助,所以肯定会继续在那里投资。显然也很兴奋模型变得更好,并兴奋能参与那个对话,现在拥有前沿模型。所以我认为我们将继续在那个领域投入大量资金,然后还有一些更有趣的东西会来。但总体而言,我只是对未来非常看好,无论是编码智能体还是通用智能体的未来,我认为这将是一个非常有趣的时期。

Yeah, I mean we definitely want to make Grok Bot better. We launched this as a beta yesterday and so tons of feedback coming in of all shapes and sizes. Our goal there is just to make this as helpful—these assistants, these bots—as helpful as we can and so definitely going to continue investing there. Obviously really excited about the models getting better too and excited to be a part of that conversation and to have frontier models now. And so I think we're going to continue to just invest a bunch in that space and then some more fun stuff to come too. But I think overall just very bullish on the future and the future of both coding agents but also as general purpose agents and I think it's going to be a really fun time.

Roshan

当然。是的。我个人非常兴奋看到作为工程师的更多性能和可靠性。这是我非常关心的事情。但是的,我们有一些非常有趣的功能正在讨论。比如我早期尝试在 Grok Bot 中黑客的一个功能是支持 iMessage。你实际上可以给你的机器人发短信。我不知道我们是否会为 Grok Bot 添加它,但我知道这是一个常见的要求。但我们肯定在考虑这样的事情,再次,心智模型是这些是同事,对吧?那么如何让你的同事不仅通过 Slack 可以访问,对吧?你可以给他们发短信,你可以打电话给他们。所以想象一个世界,你有这些永远在线的同事,你可以随时随地与他们交谈,他们只是在外为你工作,这很有趣。

Definitely. Yeah. I'm personally really excited to see more performance and reliability as an engineer. That's something I care about a lot. But yeah, we have some really interesting features that we're debating. Like one thing that I tried to hack in—I hacked into Grok Bot in the early days—was support for iMessage. You can actually text your bots. I don't know if we'll add it for Grok Bot but I know it's a common ask. But we're definitely thinking about things like this where again the mental model is these are colleagues, right? So how do you make your colleague accessible not just through Slack, right? You can text them, you can call them. So it's interesting to imagine a world where you have these always-on colleagues that you can talk to at any time from anywhere and they're just off doing work for you.

Host

天哪,我迫不及待想能给他们发短信或打电话。我看到这个梗,就像我的智能体在站会上互相交谈,他们说:‘抱歉,我整个周末都休息了。’就像你是个智能体。我不知道那到底是什么意思。

Oh my gosh, I can't wait to be able to text them or call them. I saw this meme where it's like my agents were talking to each other in their stand-up and they're like, 'Sorry, I was off all weekend.' It's like you're an agent. Like I don't know exactly what that means.

Roshan

是的,也许我们需要智能体带薪休假作为前沿。

Yeah, maybe we need agent PTO as a frontier.

Host

智能体带薪休假,关掉你的电脑。

Agent PTO, turn your computer off.

Roshan

让我们做吧。

Let's do it.

Grok 4.6基准与成本效率 Grok 4.6 Benchmarks and Cost Efficiency

Host

最后一点我想提一下,因为这真的很厉害:你们当然不只是在做 GrabBot,不只是在做应用层,也在做模型层和 Grok 4.6。基准测试在 Cursor Bench 3.2 上出来了,成绩非常亮眼,我想趁还有时间在节目里聊一聊。Grok 4.6 Extra High 得分 70.8%,平均每个任务成本 2.81 美元。作为对比,Fable 5 Max 得分 70.5%,但成本是 17.32 美元。这是巨大的变化。这个模型可能会怎样改变普通消费者与智能体、与整个 AI 的互动方式?

One last thing I did want to bring up, because this is really impressive: you guys of course are not just working on GrabBot, not just working on the application layer, but also on the model layer and Grok 4.6. The benchmarks came out on Cursor Bench 3.2 and were really impressive, and I wanted to address them here on air while we still have time. You had Grok 4.6 Extra High score 70.8% at an average cost of $2.81 per task. For context, Fable 5 Max scored 70.5% but at $17.32. This is a huge change. How does this model maybe change how the everyday consumer actually interacts with agents, with AI as a whole?

Roshan

好,你先说。

Yeah, go ahead.

Lauren

好,这确实是我最近最关心的事,因为我经常想这个问题,毕竟我在 Cursor 工作。我有无限的 token,所以可以随便把 token 用到爆,但显然我们很多客户和用户更在意成本。所以个人来说,我最兴奋的是:你有一个非常高效的模型,它和某些其他大模型一样好,但成本只是零头。我觉得这是很多领导者和工程师现在都在讨论的重要话题,也就是使用 AI 的成本不断上升。所以我认为 Grok 4.6 在这场讨论里是个很有意思的选择。每家公司对自己使用的模型组合大概都有自己的要求。

So yeah, this is definitely very top of mind for me because I think about this a lot, since I work at Cursor. I have unlimited tokens, so I can just go crazy with token maxing, but obviously a lot of our customers and our users are more cost-conscious. So personally what I'm most excited about is this idea that you have a very efficient model that is as good as some of the other big models, but at a fraction of the cost. And I feel like that's a very important topic that a lot of leaders and engineers are having right now, which is the rising cost of using AI. So I think Grok 4.6 is a really interesting choice in that discussion. Every company's going to have their own requirements, I suppose, for the type of model mix that they use.

Roshan

所以我觉得 Grok 4.6 是个非常有吸引力的选项。对吧?如果你在一些更大的模型之间考虑,那些模型也极其强大,但你想要更便宜一点的东西,Grok 就是个极好的选择。

So I think Grok 4.6 makes a very compelling option. Right? If you're considering between some of the bigger models, which are also extremely capable, but you want something a little bit cheaper, Grok is an excellent choice.

Lauren

是啊,就像如果你有 20 美元的预算来做所有 AI 任务,而每个任务的成本下降了,你就能做更多任务。所以我觉得效率这场游戏玩起来特别有意思,因为感觉你能做更多事,比如拥有更多智能体或者写更多代码。所以是的,就是这个想法——而且我觉得这正在整个行业发生,非常令人兴奋——光是能用这些 token 做更多事就酷得不行。所以是的,我们在效率上投入了大量资源,正是因为我们觉得这对这些模型来说是个非常好的方向。当然智能本身也极其重要。所以是的,我们对结果很兴奋。基准测试结果挺酷的。

Yeah, it's like if you have a budget of 20 bucks to do all of your AI tasks and the cost per task goes down, you can just do more tasks. And so I think the efficiency game is just such a fun one to play because it feels like you can just do more, like you can have more bots or write more code. And so yeah, just this idea — and I think this is happening across the industry, which is very exciting — but just being able to do more things with the tokens is wildly cool to see. So yeah, I think we are investing a ton in efficiency specifically because we think that's just a really great direction for these models to go in. And obviously intelligence matters a ton too. So yeah, we're excited about the results. The benchmark results are pretty cool.

Roshan

是啊,看到这个真的很酷。我特别兴奋的是,这么强的模型把成本降下来了。它为那些资源没那么多的初创公司提供了更好的能力,甚至对独立开发者也是如此——他们想实验,但没法自掏腰包付所有 token 费用,因为那已经有点离谱了。所以这真的开始拉平竞争环境,我对这实际意味着什么、对未来和你们所有人的产品会是什么样,感到无比兴奋。

Yeah, that was really cool to see. And no, I'm super excited specifically about lowering cost for such a great model. It provides better capabilities for startups who maybe don't have the same amount of resources, or even just indie hackers who want to experiment but can't be paying for all of your token cost out of pocket because it's just getting a little bit crazy. So it's really starting to level the playing field, and I'm incredibly excited about what that actually means and what that looks like for the future and all of your guys' products.

Host

不过 Lauren、Roshan,我真的很想感谢你们今天来节目,分享更多关于 GrabBot、Grok 4.6 以及所有有趣的更新。

But Lauren, Roshan, I really wanted to thank you guys for coming on today and sharing more about GrabBot, Grok 4.6, and all of the fun updates.

Lauren

非常感谢邀请我们。

Thanks so much for having us.

Roshan

是啊,特别好玩。如果你还没试过 GrabBot,去试试吧。真的很棒。

Yeah, super fun. And if you haven't tried GrabBot, give it a shot. It's really great.

Host

我一定得试试。

I'll definitely have to.

React编译器演示:设置与采用 React Compiler Demo: Setup and Adoption

Lauren

我猜我是午饭前的最后一位。那我们会尽量讲好。大家好,我是 Lauren,是 React 团队的工程师,负责编译器。开始之前,为了有点乐趣,我有个小请求,希望大家都能够满足我。我的幻灯片又没了。我的小请求是:我这里有一瓶水,保持水分真的很重要。所以如果每次我喝水,大家都能给我鼓个掌,我会非常感激。我们试试?趁他们修幻灯片的时候。好,谢谢大家。我想在这场演示和演讲中我可能会有点渴。我们也为帮忙的工作人员鼓个掌好吗?好,来吧。

I guess I am the final boss before lunch. So we'll try and make this good. So, hello. I'm Lauren. I'm an engineer on the React team and I work on the compiler. And before we start, to keep things a little fun, I have a small request. So I hope you all can fulfill my request. And my slides went away again. So my small request is: I have a bottle of water here, and it's really important to stay hydrated. So I'd really appreciate if every time I take a sip of water, you all could give me a clap. Should we try it? While they fix the slides. Yeah. So thank you for that. I think I might be a little thirsty during this demo and talk. Should we give a round of applause as well for the staff for helping us? Okay, there you go.

Lauren

好,我们开始吧。今天早些时候你们听 Joe 说了,我们把 React 编译器作为实验性版本开源了,你们也听 Mof 和 Satia 讲了它的工作原理,以及它在 Meta 那些大型且经过重度优化的应用(比如 Instagram.com)上的表现。把编译器推广到 Meta 的应用花了我们数周乃至数月,但今天我们只有 30 分钟,而且大家都饿了。所以我想展示如何用很小的力气就能采用这个编译器。我们会看看把编译器加到你的应用里是什么样、用它写新代码是什么感觉,并建立一些关于编译器做什么的直觉。

All right, so let's get started. So earlier today you heard from Joe that we open sourced the React compiler as an experimental release, and you saw Mof and Satia tell you about how it works and how it performs at Meta on large and really heavily optimized apps like Instagram.com. So rolling out to Meta apps took us weeks and months, but we only have 30 minutes together today and we're all hungry. So I want to show you how you can adopt the compiler with very little effort. So we're going to look at what it's like to add the compiler to your app, what it feels like to write new code with it, and build some intuition for what the compiler does.

Lauren

为了做到这一点,我们把编译器加到一个真实的开源应用里:Blue Sky。如果你不熟悉 Blue Sky,它是 Twitter 的去中心化替代品,用 React 构建。我找了在那里工作的人,而且 Blue Sky 已经有相当多的手动记忆化了。所以我不指望我们能让它快很多,但我觉得我们可以让维护性能变得容易得多,并在此过程中写出更好的 React。那我们开始吧。

So to do that, let's add the compiler to a real open-source app, Blue Sky. Now, if you're not familiar with Blue Sky, it's a decentralized alternative to Twitter and it's built with React. And I got someone who works there, and Blue Sky already has a pretty good amount of manual memoization already. So I'm not expecting that we make it way faster, but I think we can make it much easier to maintain performance and write better React along the way. So let's get started.

Lauren

好。我已经在浏览器的两个标签页里运行着 Blue Sky。左边你可以看到编译器已启用,用绿色圆圈表情标记;右边编译器已禁用,用红色圆圈表情标记。我还在 iOS 模拟器里打开了这个应用。关于编译器,我想强调的第一点是它能在所有平台上工作。Blue Sky 是一个 Expo 应用。如果你没用过,Expo 是构建跨平台 React 应用的绝佳方式。这很好,因为今天我在这里配置好编译器后,它就能在这些平台上都工作。这真的很酷。但为了让演示更简单,我就用网页版。

All right. So I already have Blue Sky running in two tabs in my browser. So on the left you can see that the compiler is enabled with the green circle emoji, and on the right the compiler is disabled with the red circle emoji. I also have the app open in my iOS simulator. So the first thing I want to highlight about the compiler is that it works on all platforms. So Blue Sky is an Expo app. And if you've never used that before, Expo is a really great way to build a React app that works on all platforms. And that's really nice because when I set up the compiler here today, it's just going to work on all these platforms. So that's really cool. But to make the demo easier, I'll just use the web version.

Lauren

好。我们要做的第一件事是安装编译器。正如你们在早先的主题演讲中看到的,从今天起我们可以从 npm 安装编译器,并更新 Babel 配置来加入编译器。我已经用 npm install babel-plugin-react-compiler 安装了这个插件,也把它加到了我们的 Babel 配置里。让我给你们看看那是什么样。如你所见,代码不多。不用担心写这个,甚至不用读它。我们的文档里有大量详细说明,教你如何配置编译器,我稍后会附上链接。

Okay. So the first thing we want to do is to install the compiler. And as you saw earlier in the keynote, starting today we can install the compiler from npm and update our Babel config to add the compiler. And I've already installed the plugin using npm install babel-plugin-react-compiler, and I've also added it to our Babel config. So let me show you what that looks like. So as you can see, it's not a lot of code. And don't worry about writing this or even reading this. We have a lot of detailed instructions in our docs on how to get the compiler set up, and I'm going to link to that later.

用编译器运行应用 Running the App with the Compiler

Host

现在编译器已经安装好,Babel 也配置好了,接下来第二件事就是运行我们的应用,确认编译器正在运行并优化我们的应用。就像我提到的,我已经把 Blue Sky 跑起来了。你可以看到左边是启用了编译器的版本,右边是没有启用的版本。我想在编译器版本上随便点一点,确认一切正常。那就随便逛逛吧。也许还可以写条推文。一条帖子,抱歉,不是推文。我很喜欢用 Memo。不错,能行。非常好。

So now that the compiler is installed and we have Babel set up, the second thing we need to do is run our app and confirm that the compiler is running and optimizing our app. So as I mentioned, I already have Blue Sky running. You can see compiler on the left, not compiler on the right. So I want to just click around a little bit on the compiler version and just double check that it all works. So let's just jump around. Maybe even write a tweet. A post, sorry, not a tweet. I love using Memo. Cool. That works. Very nice.

Host

看起来应用还能正常工作。但我们在 Meta 推广编译器时发现,为了调试,能判断编译器是否启用会非常有用。但显然你不会想在应用里加个 emoji。所以我们推荐的一种方式是直接看 React 开发者工具。就是这样。你在 React 开发者工具里首先会看到一大堆这种蓝色闪光徽章,它告诉你编译器已经自动对这个组件做了记忆化。这非常棒。我们再确认一下右边没有任何徽章。就是这样。所以右边编译器实际上是禁用的。好,很好。

So it looks like the app still works. But one thing we found through rolling out the compiler at Meta is that for debugging purposes it can be really useful to tell if the compiler is enabled or not. But obviously you don't want to add an emoji to your app. So one way that we recommend is to actually look at the React dev tools. There you go. So the first thing you'll see in the React dev tools is there's a whole bunch of these blue sparkly badges, and that tells you that the compiler has automatically memoized this component. And that's really great. And let's just double check on the right that we don't have any badges. There you go. So yeah, on the right the compiler is actually disabled. All right, great.

Host

我们已经安装了编译器,把它加进了 Babel 流程,通过开发者工具确认它能工作,然后快速检查了应用仍然正常。但我们怎么知道它真的做了点什么?它真的优化了,还是只是跳过了?一种办法是打开控制台,看 Sources 标签和稳定的 source map,翻看编译后的代码,看看发生了什么。但那样做真的很烦。所以我们回到编辑器,看看能不能稍微了解一下编译器在如何优化我们的应用。

So we've installed the compiler. We have added it to our Babel pipeline. We've confirmed that it works through the dev tools. And then we did a quick check to confirm that the app still works. But how do we know that it actually did something or anything? Like did it actually optimize or did it just skip over stuff? So one way you can do this is to open your console, look at the sources tab and the stable source maps, and look through the compiled code and try to see what would happen. But that's really annoying to do. So let's go back to our editor and see if we can learn just a little something about what the compiler is doing to optimize our app.

检查帖子控件组件 Inspecting the Post Controls Component

Host

为了做到这一点,我会通过一个叫 Post Controls 的组件来看。它就是每条帖子底部那一排按钮。你可以回复帖子、转发帖子,也可以点赞帖子。我们来看看这个 Post Controls。

So to do that I'm going to look through the lens of a component called the Post Controls component. So that's this row of buttons at the bottom of each post. So you can reply to a post, repost a post, and also like a post. So let's go take a look at that Post Controls.

Host

好,为了更好地理解编译器在做什么,我为了这个演示临时写了一个小小的 IDE 扩展。这不是编译器的官方 VS Code 扩展,只是帮我更好地向你展示编译器在做什么。但实际上,做这个扩展也给了我们一些关于官方 VS Code 体验可以长什么样的新想法。这挺酷的。我们来看看编译器对这个组件做了哪些优化。

Okay, so to better understand what the compiler is doing, I hacked on a little small IDE extension just for this demo. And this isn't the official VS Code extension for the compiler, but it's just something to help me show you what the compiler is doing better. But actually, through building this, it's given us some new ideas on what an official VS Code experience could look like. So that's pretty cool. So let's take a look and see what the compiler has done to optimize this component.

Host

右边有一大堆代码。不用觉得你需要全部读完,但这基本上展示了编译器编译出来的结果。判断一个组件或 hook 是否被编译器优化的一种方式,是看顶部这个小美元符号变量。不用担心怎么用它,它不是给人直接用的,只是给编译器用的。你可以把它想成一个大数组,编译器用它来高效地缓存和读取值。

So there's a whole bunch of code on the right. So don't feel like you need to read it all, but this essentially shows you what the compiler has compiled. So one way to tell if a component or hook was optimized by the compiler is to look for this little dollar sign variable up top. And don't worry about how to use this. It's not meant to be used directly. It's really just for the compiler. So one way you can think about this is it's just a big array of values that the compiler can use to cache and retrieve values efficiently.

Host

我们还可以看到,如果我在左边往下滚一点,编译器尽可能保留了原始代码的写法。所以调试时你可以翻看它,看起来很熟悉,但它确实做了优化,只是稍微难读一点。到处都是美元符号,还有一些不太好读的 if 条件。这没关系,因为有更好的方式来理解它。我先把这个面板关掉,然后用那种方式来看。

We can also see if I scroll down a little bit on the left that the compiler as much as possible preserves the original code as it was written. So when you're debugging you can look through this and it looks familiar, but it does do optimization. So it's just a little bit harder to read. There's a whole bunch of dollar signs everywhere and there's these kind of hard to read if conditions. So that's okay because there's a better way to understand it. So I'm going to close this panel real quick and do that.

解读编译器输出 Reading the Compiler's Output

Host

所以我在我那个山寨 IDE 扩展里又加了一个视图,帮我一眼看清编译器在做什么。你首先会看到组件名旁边有个闪光 emoji。就像 React 开发者工具一样,这告诉你这个组件已经被 React 编译器自动记忆化了。

So I added another view to my little bootleg IDE extension to just help me see at a glance what the compiler is doing. So the first thing you'll see is there is this sparkly emoji next to the component name. And just like the React dev tools, this tells you this component has been auto-memoized by the React compiler.

Host

我们还有这些 dep 标签,是 dependency(依赖)的缩写。意思是这个值是另一个值的依赖。也就是说,当这些依赖变化时,需要这些依赖的输出值也会更新。然后我再往下滚一点,你还会看到——在哪呢?——这个 RTV reactive 标签,它告诉你这个值依赖于我们刚才在代码里看到的那些依赖中的一个或多个。

We also have these dep labels, which is short for dependency. And that means that this value is a dependency of some other value. So that means that when these dependencies change, the output values that require these dependencies will also update. And then if I scroll down a little bit more, you'll also see — where is it? — this RTV reactive label, and that tells you that this value depends on one of those or one or more of those dependencies that we just saw earlier in the code.

Host

我想稍微看看这个变量,好让我们再深入一点。如果我把鼠标悬停在这个值上,你可以看到编译器说它是响应式的,或者说它依赖于 theme.palette.default.postControl,这很合理,对吧?因为这又是 Post Controls 组件,也就是每条帖子底部那一排按钮。我们要确保根据我们选择或选中的主题,使用正确的颜色。默认控件颜色也是一个依赖,这挺有意思的。因为它在后面的 JSX 里被用来决定按钮的正确颜色。

So I want to take a look at this variable a little bit just so we can dive a little bit deeper here. So if I hover over this value, you can see that the compiler says it's reactive, or it depends on theme.palette.default.postControl, which makes sense, right? Because again this is the Post Controls component, which is the row of buttons at the bottom of each post. We want to make sure that depending on the theme that we have chosen or selected, the correct colors are used. The default control color is also a dependency, which is pretty interesting. And that's because it's used later on in the JSX to determine the correct colors for the buttons.

Host

但还有件有意思的事。这个变量和值已经被我们用 React.useMemo 手动记忆化了。但真正有意思的部分在依赖数组这里,因为我们原本写的是只依赖 theme 对象。但编译器说不是 theme 对象,而是 theme.palette.default.postControl。我们再看看 JS 输出,好理解发生了什么。我往下滚找到这里。就在这儿。

But here's something also interesting. This variable and value has already been manually memoized with React.useMemo. But the really interesting part is here in the dependency array, because originally we wrote this as just depending on the theme object. But the compiler says it's not the theme object. It's theme.palette.default.postControl. So let's look at the JS output again just so we can understand what's going on. So let me scroll down and find this. That's over here.

Host

你首先能看到的是编译器移除了手动记忆化。这里完全看不到 useMemo。如果你看这个 if 条件,这里的检查,你可以看到它和这个值所依赖的东西是对应的。所以这个条件告诉你这块记忆化依赖什么。就像我提到的,它和我们在手动记忆化里指定的不一样,因为编译器发现我们可以只依赖那个属性的变化,而不是整个 theme 对象的变化,你可以想象整个对象可能变化得更频繁一些。

So the first thing you can see is the compiler has removed the manual memoization. You don't see useMemo here at all. And if you look at the if condition, this check over here, you can see that it lines up with what this value depends on. So this condition tells you what this block of memoization depends on. And as I mentioned, it's different from what we specified in the manual memoization because the compiler has figured out that we can just depend on the property changing and not the entire theme object changing, which you can imagine might just change a little bit more frequently.

Host

这是一个很小的例子,但它向你展示了编译器比我们手工做的时候记忆化得更细粒度。组件的其余部分也是一样。编译器会准确找出需要记忆化的内容以及它们需要依赖什么。所以关于编译器要记住的第二件关键事情是,它能比我们更高效地进行细粒度记忆化。

So this is a really small example, but it shows you that the compiler has memoized this more granularly than we often do by hand. And the same will go for the rest of the component. The compiler will figure out exactly what needs to be memoized and what they need to depend on. So the second key thing to remember about the compiler is that it can granularly memoize much more efficiently than we can.

编译器演示简介 Intro to the compiler demo

Lauren

事实证明,计算机在这类细粒度的追踪和优化上比我们强得多。好,现在我们对编译器在做什么有了点概念。我们知道它会扫描我们的代码,找出依赖关系,然后对值做记忆化,使得只有当真正影响它的依赖发生变化时,这些值才会变。

Computers, it turns out, are way better at this type of granular tracking and optimization than we are. Okay, so now we have a little bit of an idea what the compiler is doing. We know that it looks through our code, it figures out what the dependencies are, and then it memoizes values such that they only change when the dependencies that actually affect it change.

Lauren

现在我想看看,在编译器的存在下添加新代码是什么感觉。让我把所有东西都关掉。

So now I want to take a look at what it feels like to add new code with the compiler. So let me turn everything off.

Lauren

我想加的功能会放在这个帖子控件组件上,再提醒一下,就是这里这一排按钮。让我回到我的个人主页。

So the feature I want to add is going to be on this post controls component, which, as a reminder again, is like this row of buttons here. So let me go back to my profile.

Lauren

有时候,你知道,我刷时间线,看到有人发的东西我完全不认同,比如这条帖子,我就会偷偷想给这条帖子点个踩,你懂吧?

So sometimes, you know, when I look at my timeline and I see something that someone posted that I just disagree with, like this post right here, I secretly want to dislike that post, you know?

Lauren

所以我想把这个功能做成只在本地生效的东西,这样我就能私下里给帖子点踩,别人都不知道,你知道,就为了让我这颗冰冷死寂的心感受到点什么。那我们就在帖子控件里加一个踩按钮吧。

So I kind of want to add that feature as a local-only thing so I can dislike posts in private without anyone else knowing, you know, just to feel something in my cold dead heart. So let's add a dislike button to the post controls.

Lauren

好,我们往下翻到 JSX。这里 JSX 很多,但这基本上就是点赞按钮的一大块代码。我要做的就是紧挨着它加一个踩按钮。我已经在这里准备好了一些东西,记得保存。

All right. So let's go down to the JSX. So there's a lot of JSX here, but this is essentially a big block of code for the like button. So what I want to do is just add the dislike button right next to it. So I've already prepared something here and remember to save.

Lauren

如果你没见过这个,View 组件来自 React Native Web,它让这段代码能同时在网页和移动端运行。如果我们点这个踩按钮,它现在什么都不返回。所以我们得把它实现出来。

So if you've never seen this before, the View component is from React Native Web and that allows this code to run on both web and mobile. And if we click on the dislike button, it doesn't return anything right now. So we have to implement it.

Lauren

首先,我已经准备好了一些主题变量,就为了让它好看。让我把它们粘进去。和帖子控件一样,这只是确保根据所选的主题,我们用的是正确的颜色。

So first of all, I already have some theme variables prepared just so it looks good. So let me just paste those in. And just like the post controls, this just makes sure that depending on the theme that's chosen, we use the correct colors.

Lauren

我们还需要返回一些 JSX。再说一次,这看起来代码很多,但其实就是一个按钮,里面包着一个图标,一个拇指向下的图标,还有一些显示踩数的文字。

We also need to return some JSX. And again, this looks like a lot of code, but really it's a button that wraps an icon, a thumbs down icon, and some text that shows you the dislike count.

Lauren

看起来很多,但这其实很好,因为它包含了很多好东西,比如无障碍支持。而且你知道,编译器能直接处理这一切,对吧?哪怕它看起来很复杂。

So it looks like a lot, but this is really good because it has a lot of good stuff like accessibility. And you know, the compiler can just handle all of this, right? Even though it looks complicated.

Lauren

我们首先要考虑的是,好,我们想给帖子点踩。那怎么做呢?我们知道需要一些状态,对吧,在每次点这个按钮时递增。那我们就加上它,然后初始化为零。

So the first thing we got to think about is, all right, we want to dislike post. So how do we do that? So we know that we need some state, right, to increment whenever we click on this button. So let's just add that and then we'll initialize it to zero.

Lauren

于是我们有了一个踩数和一个设置踩数的函数。在我们的 onPress 处理函数里,我们就把踩数设成当前计数加一。然后保存,回到浏览器。刷新。我们就能看到,好耶。现在我们可以给这条帖子点踩了。

So we have a dislike count and a set dislike count. So on our onPress handler we'll just set the dislike count to be whatever the count is plus one. And then we'll save and go back to our browser. Refresh. And we can see, hooray. Now we can dislike this post.

Lauren

我爱 useMemo。这个人错得离谱。好,我们能看到这能用了。酷,我们搞定了。

I love useMemo. This person is so wrong. Okay. So we can see that this works. And cool. We're done.

Lauren

不。你看,我加上它之后,其实并不喜欢。你看,比这种点赞帖子更让我讨厌的,是不必要的重渲染。每次一个按钮重渲染,我都睡不着觉,对吧?我内心在咆哮。还有谁也讨厌不必要的重渲染吗?

No. You see, now that I've added it, I don't really like it. You see, the thing that I dislike more than like posts like this is unnecessary rendering. It keeps me up at night every time a button rerenders, right? Like, I'm raging inside. Like, anybody else hate unnecessary rendering?

Lauren

所以我想做的是,让这个踩数在按钮每次重渲染时自动增加,但我同时也仍然希望能点它,就为了,你知道,表达我的愤怒。那我们来把它做出来。

So what I want to do is I want to make this dislike count automatically go up whenever the button rerenders, but I also still want to be able to click on it just to, you know, express my anger. So let's build this.

Lauren

谢谢。谢谢。好。哇,这个演讲进行得太顺利了。

Thank you. Thank you. All right. Wow, this talk is going so well.

Lauren

好。要做到这个,我当然得删掉 useState,因为我们不想让这个数字只在点按钮时增加。我们想让它每次按钮重渲染时都增加。

So, okay. To do this, I'm going to need to delete the useState, of course, because we don't just want the number to go up only on clicking the button. We want it to go up every time the button rerenders.

Lauren

所以,要做到这个,我得在这里打破一些 React 的规则。所以,别在家里模仿。好,我做了什么?我加了一个 ref 来存一个数字,每次组件渲染时,我们就把这个数字加一,然后我们就把踩数设成这个数字。

So, to do this, I need to break some rules of React here. So, don't try this at home. Okay, so what did I do? So I added a ref to hold on to a number, and every time the component renders, we'll increment that number by one, and then we just set the dislike count to whatever the number is.

Lauren

这挺不靠谱的,因为它打破了 React 的一条规则,就是不要在渲染期间读写 ref,因为这会破坏这个组件是纯组件的预期。

And this is pretty sketchy because it breaks one of the rules of React, which is to not read and write to refs during render, because it breaks the expectation that this component is a pure component.

Lauren

现在,一些眼尖的开发者可能注意到了,我加上这段代码时,代码下面出现了一条红色下划线。这里就是一个编译器提供的 lint 示例,它说 ref 值的 current 属性可能不能在渲染期间访问。

Now, some of you eagle-eyed developers may have noticed that when I added this code, we got a red underline underneath our code. So, here we have an example of a lint provided by the compiler, and it says ref values, the current property, may not be accessed during render.

Lauren

但编译器不只是警告我们,它还能检测到我们在做不靠谱的事,然后安全地跳过这个组件,继续优化其他所有东西。让我再看一下编译输出,给你们展示会发生什么。

But the compiler doesn't just warn us, it can also detect that we're doing something sketchy and then safely skip over this component and continue optimizing everything else. So let me take a look at the compile output again just to show you what happens.

Lauren

我刚把两个功能都打开了,比如可视化功能和输出。确认一下,你能看到我们不再有 const dollar 变量了,这意味着编译器没有在优化这个组件,把它原样留下了。同样在左边,我们也没有那个闪亮的小表情了。

So I just enabled both of the features, like the visualization feature and the output. And so just to confirm, you can see that we no longer have the const dollar variable, which means the compiler isn't optimizing this component and left it untouched. And similarly on the left we no longer have our little sparkly emoji.

Lauren

这有点糟,对吧?你知道,这个组件之前一直在被优化,但现在没有了。但没关系,因为尽管编译器假设你遵守 React 规则来优化你的组件,它也能判断出你打破了规则,然后安全地跳过它。

So that kind of sucks, right? Like, you know, this component was being optimized before but now it's not. But that's okay because even though the compiler assumes that you follow the rules of React to optimize your components, you can also tell when you've broken the rules and then just skip over it safely.

Lauren

那我们就继续往下,暂时忽略这条红线。让我把这个关掉。让我按保存。我们还得修一下 onPress 处理函数,因为我刚把 setDislikeCount 删了。

So let's just keep moving on and ignore this red line for now. And let me turn this off. So let me hit save. And we still need to fix our onPress handler because I just deleted the setDislikeCount.

Lauren

我想做的是,每当我点这个按钮,我就想让它重渲染。要做到这个,我们可以再加一个 useState。哦,这个提示框太大了。这应该能让它重渲染。

So what I want to do is, whenever I click on the button, I just want to make it rerender. So to do that we can add another useState. Oh, this tooltip is so big. And that should make it rerender.

Lauren

好,我们回去看看进展。好,酷。现在你能看到,这次踩按钮从 1 开始,正如预期,我们在它渲染时把数字加一。所以页面加载时它显然从 1 开始。

Okay, let's go back and check on our progress. All right, cool. So now you can see that the dislike button starts at one this time, which as expected, we increment the number when it renders. So it obviously starts at one when the page loaded.

Lauren

但现在我们看看,在未编译的版本里到处导航时,这个踩数会发生什么。我就到处跳一跳,你知道,去这里,去那里。有点慢。所以,如你所见,它在慢慢往上涨。好,对,它涨了。

But now let's see what happens to this dislike count as we navigate around the non-compiled version. So I'm just going to jump around, you know, go here, go there. It's taking a while. So, as you can see, it's kind of going up slowly. Okay. Well, yeah, it went up.

Lauren

所以你能看到,编译器,抱歉,是这个应用在我们每次导航时都在重渲染这个按钮,这真的很不好,我们就是不喜欢这样。

So you can see that the compiler, or sorry, the application is rerendering this button every time we navigate around, which is really not nice and we just don't like this.

Lauren

我还想给你们看看我点点赞按钮时会发生什么。我们能看到这个。让我放大。让我狂点这个。调用栈。这可不好。但你能看到,每次我点点赞按钮,踩数实际上每点一次赞就涨三次。

So I also want to show you what happens when I click on the like button. So we can see this. Let me zoom in. Well, let me click on this a bunch. Call stack. That's no good. But you can see every time I click on the like button, the dislike count actually goes up by three times per like.

Lauren

所以我们真的很讨厌这条帖子。这是一条糟糕的帖子。但我想给你们看看在编译器版本里会发生什么。那我们也到处导航一下。

So we really dislike this post. This is a terrible post. But I want to show you what happens in the compiler version. So let's just navigate around as well.

编译器优化与React规则 Compiler Optimization and React Rules

Lauren

我也会点击“喜欢”按钮。对吧,很棒吧?现在你们有些人可能在想,等等,编译器不是没有优化这个“不喜欢”按钮吗?那为什么这个还是 1 呢?记住,我们在“不喜欢”按钮中违反了 React 的一条规则,所以我们在输出中看到编译器不再优化它。它仍然被优化的原因是,PostControls 组件——也就是“不喜欢”按钮的父组件——仍然被优化,编译器在 PostControls 组件的所有子组件周围添加了相当于 React.memo 的东西。所以即使这个组件没有被优化,我们仍然从使用编译器中获得了很多好处,这真的很棒。

I'll also click the like button. And yeah, awesome, right? So now some of you might be wondering, like, wait, didn't the compiler just not optimize this dislike button? So how come this is still one? So remember that we broke a rule of React right in the dislike button, and so that we saw in the output that the compiler is no longer optimizing it. So the reason this is still optimized is because the PostControls component, which is the parent of the dislike button, is still being optimized, and the compiler is adding the equivalent of React.memo around all of the children of the PostControls component. So even though this component isn't being optimized, we still get a lot of the benefits from using the compiler, which is really great.

Lauren

但如果我回到编辑器,你知道,我们怎么处理这条红线?因为,就像,我不知道你怎么样,但每次我看到代码下面有波浪红线,我就觉得非得修复它不可,但我不能。这就像,你知道,猫死了。我就想,哦,一条红线。确实,试图修复 ESLint 规则检测到的所有 React 规则违规真的很诱人。但正如你在应用中也看到的,如果没有 bug,并不严格需要急于修复这些,因为编译器可以检测许多此类违规情况,然后安全地跳过它,同时继续优化其他组件。

But if I go back to my editor, you know, what do we do about this red line? Because, like, you know, I don't know about you, but every time I see a squiggly red line underneath my code, I feel so compelled to fix it, and I can't. This is like, you know, cat death. I'm like, oh, a red line. And it's true, it can be really tempting to try and fix all of these rules of React violations that the ESLint rule detects. But as you also saw in the app, it's not strictly necessary to rush into fixing these if there are no bugs, because again, the compiler can detect many cases of such violations and then just safely skip over it while continuing to optimize other components.

Lauren

所以如果我打开 memo 可视化确认一下,对吧,我们没有那个闪亮的徽章。所以如果我们愿意,我们可以稍后回来修复这个,对吧?但为了演示,我们就说我们已经完成了,现在回来修复这个。那么,我们能做什么?我们可以做的一件事是提取这段代码。所以,如果我删除这个,你会看到我们的闪亮徽章立即回来了,因为编译器看到这段代码不再可疑。所以,我们把它加回来作为一个新的 hook。我们叫它 useRenderCountUnsafe。你也可以叫它 useRenderCountDoNotUseOrYoullBeFired,我想,如果你喜欢的话。所以,我们把它加回来。你可以看到我们的红线回来了,但这次只是围绕 useRenderCountUnsafe hook,而不是我的“不喜欢”按钮。然后我们更新这个来使用新 hook。如你所见,我们仍然被优化了。所以万岁,我们完成了——我们取得了一些进展,你知道,我们帮助编译器编译了我们应用的更多部分。这真的很棒。

And so if I turn back the memo visualization just to confirm, right, we don't have the sparkly badge. So if we want to, we can come back and fix this later, right? But for the sake of the demo, let's just say that we've already done that and we're now coming back to fix this. So, what can we do? So, one thing we can do is to extract this code. So, if I just delete this, you'll see that our sparkly badge immediately came back because the compiler saw that this code is no longer sketchy. So, let's just add that back as a new hook. We'll call it useRenderCountUnsafe. You can also call it useRenderCountDoNotUseOrYoullBeFired, I guess, if you like that. So, let's just add that back. And you can see that our red lines are back, but this time it's just around the useRenderCountUnsafe hook and not on my dislike button. And then let's just update this to use that new hook. And as you can see, we are still optimized. So hooray, we have done—we've made some progress and, you know, we've helped the compiler compile a little bit more of our application. So that's really awesome.

Lauren

但我们怎么知道编译器正确记忆化了呢?比如我们怎么知道它不是仅仅保留数字 1 或 2 然后永远缓存那个?让我快速刷新两个标签页来重置所有计数。首先我们点击这里的“喜欢”按钮。你可以看到喜欢计数没有增加。记住这个按钮的 onPress 处理函数不直接修改计数。它只是触发重新渲染。所以这意味着按钮仍然正确地依赖于来自我可疑 hook 的“不喜欢”计数。我们再把主题从浅色改为深色。在我做之前你可以看到计数当前是 1。所以让我们把主题从浅色改。抱歉会很亮。捂住眼睛。好了,没事了。好的。你可以看到计数增加到 2,并且“拇指向下”图标颜色正确。它翻转了。所以这意味着“不喜欢”计数——或者抱歉,图标——仍然是响应式的,它仍然依赖于主题变化,并且正确执行。非常酷。让我切换回深色,然后你会看到它也回到 3。好的,酷。所以我们验证了编译器为我们正确记忆化了,它只对实际影响它的东西重新渲染,而且我们没写任何 memo 就做到了,这真的非常棒。

But how do we know that the compiler is memoizing correctly, right? Like how do we know it's just not holding on to the number one or two and then just caching that forever? So let me just refresh both tabs real quick to reset all the counts. So first let's click on the like button here. And you can see that the like count doesn't go up. And so remember that the onPress handler for this button doesn't modify the count directly. It just triggers a rerender. So that means that the button is still correctly depending on the dislike count that comes from my sketchy hook. Let's also change the theme from light to dark. And you can see before I do that that the count is currently one. So let's change the theme from light. And I'm sorry it's going to be really bright. Cover your eyes. Okay, we're good. All right. So you can see the count went up to two and the thumbs down icon is the correct color. It flipped. So that means that the dislike count—or sorry, the icon—is still reactive and it still depends on the theme changing and it does it correctly. Very cool. So let me switch it back to dark and then you'll see that go back to three as well. All right, cool. So we verified that the compiler has memoized this correctly for us and it only rerenders for the things that actually affect it and we did that without writing any memo ourselves which is really really nice.

Lauren

但哦,顺便说一下,如果你记得我们还有 iOS 模拟器在运行,它不正确。我想我的 iOS 某处断开了。但无论如何,重点是,因为 Bluesky 是一个 Expo 应用,它运行在所有平台上,我们刚刚做的工作将在所有这些平台上免费工作,这真的很好,因为我是一个相当懒的开发者。

But oh, by the way, if you remember we still have our iOS simulator running and it is not correct. I think my iOS somewhere got disconnected. But anyway, the point is, because Bluesky is an Expo app and it runs on all platforms, the work that we just did will work on all of these platforms for free, which is really nice because I'm a pretty lazy developer.

Lauren

好的,让我们回到幻灯片。好的。所以,我想你现在可以看到编译器真的帮助 React 更接近其愿景:伟大的开发者体验,易于构建,并且你知道,实现伟大的用户体验。编译器在所有平台的所有现代 React 应用上工作。所以我们之前做的在 Web 和移动端都有效,编译器还可以比我们手动更有效地记忆化,同时保持记忆化对代码更改的弹性。如果你的代码库遵循 React 规则,采用编译器可能相当直接。如你所见,我不需要重写任何东西。没有新的 API,因为编译器理解纯 JavaScript 和 React。

Okay, so let's go back to our slides. All right. So, I think you can see now that the compiler really helps React move closer to its vision of great developer experience that's easy to build and, you know, enables great user experience. And the compiler works on all platforms on all modern React apps. So, what we did earlier works on both the web and on mobile and the compiler can also memoize far more effectively than we can do by hand while also keeping that memoization resilient to code changes. If your codebase follows the rules of React, adopting the compiler could be pretty straightforward. And as you saw, I didn't need to rewrite anything. There's no new APIs because the compiler understands plain JavaScript and React.

Lauren

所以,让我们回顾一下。我们刚刚将编译器放入了整个 Bluesky,而无需重写任何东西。如果你看看启用编译器的 PR,只是几行配置和安装一些包。我们添加了一个新功能来表达我们对这种重新渲染的厌恶,而完全不用担心 memo。所以这看起来很容易。我保证我没有脚本化喝水。好的,所以它容易是因为 Bluesky 代码库遵循 React 规则。但如果你的代码库不遵循,可能会有点困难,需要调试。我提到的规则是你们中一些人可能很熟悉的规则。但如果你不熟悉也没关系,因为你可以查看上面的链接,了解更多关于这些 React 规则。这些规则不仅帮助你编写更好的 React,还帮助为编译器创建一个安全的空间来优化,如果你想获得更高质量的应用程序,遵循它们非常重要,而且这也使得采用编译器更容易。

So, let's recap. We just dropped in the compiler to all of Bluesky without having to rewrite anything. And if you look at the PR to enable the compiler, it's a few lines of config and installing some packages. And we added a new feature to express our hate for this rerendering without worrying about memo at all. So that seems kind of easy. I promise I didn't script the drinking. Okay, so it's easy because Bluesky codebase follows the rules of React. But if you have a codebase that doesn't, it might be a little bit more difficult and require debugging. And the rules that I'm referencing are the rules which some of you are probably quite familiar with. But it's okay if you're not because you can check out the link above and you can find out more about these React rules. These rules don't just help you write better React, but they also help you create a safe space for the compiler to optimize and it's really important to follow them if you want a better quality application, but it also makes it easier to adopt the compiler as well.

Lauren

正如我们在演示中也看到的,编译器还附带一个 ESLint 插件。这样就能在你的编辑器中直接显示编译器诊断信息,这真的很棒。因为这是我们第一次能够在你的代码中显示 React 规则错误。当前的 React ESLint 规则只显示 hooks 规则,这只是我们规则的一个子集。作为发布的一部分,我们还包含一个健康检查脚本,它会让你大致了解采用编译器需要多少努力。当然它并不完美,但它可以给你一些信号,判断这可能需要几天还是几周的努力。所以你们中一些人可能还想知道编译器究竟如何开箱即用地在任何 React 应用上工作。

And as we also saw in the demo, the compiler also ships with an ESLint plugin. So that surfaces the compiler diagnostics right inside of your editor, which is really nice. Because it's the first time we've been able to show rules of React errors in your code. The current React ESLint rules only show you the rules of hooks, which is only a subset of our rules. As part of the release, we're also including a health check script which will give you a little sense of how much effort it'll take to adopt the compiler. It's not perfect of course, but it can give you some signal into whether this might take a few days or a few weeks of effort. So some of you might also be wondering how exactly does the compiler just work out of the box on any React app.

建立编译器直觉 Building intuition for the compiler

Lauren

我们怎么信任它?你不需要了解编译器背后的理论就能使用它,但我认为建立对它行为的直觉很重要。所以我们先来看看今天是怎么手动做记忆化的,以此建立这种直觉。

How do we trust it? You don't need to know the theory behind the compiler to use it, but I think it's important to build an intuition for what it's doing. So let's build this intuition by first looking at how we do manual memoization today.

Lauren

在今天的 React 里,当一个组件的 state 变化时,React 会重新渲染那个组件及其所有子组件。这听起来很多,而实际上 React 通常足够快,大多数时候直接重新渲染也没问题。但当然,我们都知道也有很多情况下重新渲染确实会严重损害性能。

So in today's React, when a component state changes, React is going to rerender that component and all of its children. And this sounds like a lot, and in practice, React is usually fast enough that most of the time it's fine to just rerender. But of course, we all know that there are many occasions as well where rerenders can really hurt performance.

Lauren

所以你不需要理解所有这些,但我们来看一个例子,看看编译器会自动推断出什么。

So you don't have to understand all this, but let's take a look at an example and see what the compiler figures out automatically.

Lauren

首先有几个没有任何依赖的值。它们是静态的,所以永远不需要重新计算。然后还有一些值依赖于这里的 online count,这个值来自第一行的 hook。有趣的是:一个被缓存的值也可以成为另一个值的依赖。

So first there's a couple of values that don't have any dependencies. These are static so they never need to be recalculated. Then we also have values that depend on the online count here, which is a value that comes from the hook in the first line. And here's something interesting: a value that's cached can also become a dependency of another value.

Lauren

第三,我们还可能有依赖于 friends prop 的值。最后,返回的整体 JSX 视图也可以依赖于那些本身就是响应式的值。

Third, we can also have values that depend on the friends prop. And finally, the overall view of JSX that gets returned can also depend on values that are themselves reactive values.

Lauren

但先忘掉那些框框,对吧?有点让人困惑。我们就再看一眼原始代码。这是一个非常简单的例子,但它如此纯粹地描述了你 UI 的样子。

But forget all of those boxes, right? It's kind of confusing. So let's just look at the original code again. This is a really simple example, but it's such a pure description of what your UI looks like.

Lauren

所以理解编译器的一种方式是,它是一个自动响应式编译器。React 有时过于响应式,因为你改任何东西,所有东西都跟着变。编译器现在会自动加入恰到好处的响应式,并让更新默认就很快。

So one way to think about the compiler is that it's an auto reactivity compiler. React is too reactive sometimes because when you change anything, everything changes. The compiler now automatically adds just the right amount of reactivity and it makes updates fast by default.

Lauren

所以在 React 里,你用普通 JavaScript 值描述 UI,编译器会自动为你处理响应式和性能。于是你可以忘掉响应式,剩下的就只是 React。耶。

So in React, you describe your UI using plain JavaScript values and the compiler automatically takes care of reactivity and performance for you. So you can forget about reactivity and what you're left with is just React. Yay.

记忆化昂贵计算 Memoizing expensive calculations

Lauren

好。今天你可能还需要记忆化的另一种情况是,你有开销很大的计算。比如,假设你出于某种原因需要在客户端同步处理非常大量的数据。运行这个函数要花很长时间。所以你不想在每次渲染时反复运行它。因此对它做记忆化非常重要。

All right. Another case where you may also need memoization today is if you have expensive calculations. So for example, let's say that you, for whatever reason, need to synchronously process a really large amount of data on the client. And running this function takes a long time. So you don't want to run this repeatedly on every render. So it's really important to memoize this.

Lauren

编译器也会处理这一点,因为你可以看到这个昂贵的计算在渲染期间被用到了。当你把它和针对重新渲染的优化结合起来,编译器性能收益的很大一部分就来自这里。

The compiler also handles this since you can see that this expensive calculation was used during rendering. And when you combine it with optimizing for rerendering, this is where a really large part of the compiler's performance benefits come from.

Lauren

不过这个例子有一点要注意:编译器不会记忆化所有东西。它只记忆化 React 组件和 hook。所以我前面提到,编译器理解 React 的规则。因此不遵守这些规则的普通函数不在编译器的处理范围内,如果它们开销大,应该在 React 之外做记忆化。

One thing to note with this example though: the compiler doesn't memoize everything. It only memoizes React components and hooks. So I mentioned earlier that the compiler understands the rules of React. So ordinary functions which don't abide by those rules are out of scope for the compiler and should be memoized outside of React if they are expensive.

React的愿景与结语 React's vision and closing

Lauren

所以当你把这两项优化结合起来,自动推断依赖和响应式以跳过重新渲染,以及在渲染期间记忆化昂贵计算,React 编译器让我们更接近 React 的愿景:你继续使用普通 JavaScript 值,它们保持在恰到好处的响应式水平,让你轻松构建启动快、交互响应灵敏的优秀用户体验。

So when you combine these two optimizations, automatically figuring out dependencies and reactivity to skip rerendering and memoizing expensive calculations during rendering, the React compiler gets us closer to React's vision, where you continue to work with plain JavaScript values that stay at just the right level of reactivity, making it easy to build great user experiences that start up fast and have responsive interactions.

Lauren

如果你有兴趣更深入地了解我们在编译器里做的许多不同类型的优化,请一定去看明天 Mofay 和 Safia 的深度讲解。会很精彩。

If you're interested in gaining a deeper understanding into the many different kinds of optimizations that we do in the compiler, please definitely check out Mofay and Safia's deep dive tomorrow. It's going to be awesome.

Lauren

但我们在一起的时间快结束了。这里有一张幻灯片,你们都可以发推。请去看看我们关于编译器的文档,希望你们试用得开心。

But our time together is coming to an end. So here's a slide that you can all tweet. So please check out our docs on the compiler and I hope you have a really good time trying it out.

Lauren

我们等幻灯片切回来。哦。

While we wait for the slide to come back. Oh.

互动版:逐字朗读 + 针对本期提问 →