> 2021年07月04日信息消化 ### The Untold Story of SQLite 原文:[The Untold Story of SQLite](https://corecursive.com/066-sqlite-with-richard-hipp/#) On today’s show, I’m talking to **Richard Hipp** about surviving becoming core infrastructure for the world. SQLite is everywhere. It’s in your web browser, it’s in your phone, it’s probably in your car, and it’s definitely in commercial planes. It’s where your iMessages and WhatsApp messages are stored, and if you do a find on your computer `computadora` for *.db, you’ll be amazed at how many SQLite databases you find. Today, Richard is going to share his story. It’s the story of creating a small open source project `proyecto` and having it grow beyond your wildest ambitions. It’s the story of following that success wherever it leads: From relationships `relaciones` with tech-giants to interesting testing procedures and more. 在今天的节目中,我和Richard Hipp讨论了生存成为世界的核心基础设施。SQLite无处不在。它在你的网络浏览器中,在你的手机中,它可能在你的汽车中,而且它肯定在商业飞机中。它是你的iMessages和WhatsApp信息存储的地方,如果你在你的电脑上查找*.db,你会对你找到的SQLite数据库之多感到惊讶。 今天,理查德将分享他的故事。这是一个关于创建一个小型开源项目并使其发展到超出你最疯狂的野心的故事。这是一个跟随成功的故事,无论它通往何处。从与技术巨头的关系到有趣的测试程序等等。 - **00:00** - [Introduction](https://corecursive.com/066-sqlite-with-richard-hipp/#introduction) - **01:45** - [The Battleship](https://corecursive.com/066-sqlite-with-richard-hipp/#the-battleship) 战舰 **Adam:** Richard was a contractor for Bath Iron Works working on software for the DDG-79 Oscar Austin. That is a battleship, the type that protects a fleet by being armed to the hilt. **Richard: **There’s a big, complex ship, and stuff’s always breaking. Suppose a pipe ruptures. You need to isolate that damage by closing valves on either side of the pipe, but then you also need to open valves elsewhere to restore the working fluid to other systems that are downstream so that they don’t go offline, and locating all those valves and whether you open them or close them can get very complicated, and so Automated Common Diagrams is a program that says, “Oh, here’s the problem. Here’s the valves you close. Here’s the valves you open. Here’s where they’re located.” That was the original problem, and all the data for where all the pipes are running and all the valves are located, that was in the database. The computer was already installed on the ship. We didn’t have any control over that. The database was already installed on the ship. We didn’t have any control over that. We just had to use what was there. - **02:49** - [NP-Complete Problems](https://corecursive.com/066-sqlite-with-richard-hipp/#np-complete-problems) **Richard:** No. No, and of course, it’s a war ship, so, of course, things are always breaking and they use it all the time, but the idea is it’s supposed to be able to work if you take battle damage, so it’s more than one pipe breaking and there’s going to be a lot of stuff broke, and people are going to be crazy and there’s going to be smoke and blood and chaos, and in a situation like that they don’t want a dialog box that says, “Cannot connect to database server.” That’s just not what they want to see, so it needs to be reliable. All we’re doing is reading the data into RAM. We’re not doing transactions. We’re not doing anything like that. It’s just, we’re pulling a bunch of data into memory so that we can solve this problem. Why do we even need a server? Why can’t I pull this directly off the disk drive? That way if the computer is healthy enough, it can run our application at all, we don’t have dependencies that can fail and cause us to fail, and I looked around and there were no SQL database engines that would do that, and one of the guys I was working with says, **“Richard, why don’t you just write one?” “Okay, I’ll give it a try.”** I didn’t do that right away, but later on, it was a funding hiatus. This was back in 2000, and if I recall correctly, Newt Gingrich and Bill Clinton were having a fight of some sort, so all government contracts got shut down, so I was out of work for a few months, and I thought, “Well, I’ll just write that database engine now.” 理查德:不。不,当然,这是一艘战舰,所以,当然,东西总是坏的,他们一直在使用它,但我们的想法是,如果你在战斗中受到伤害,它应该能够工作,所以它不止一个管道坏了,会有很多东西坏了,人们会很疯狂,会有烟雾、血和混乱,在这样的情况下,他们不希望有一个对话框说,"无法连接到数据库服务器"。这不是他们想看到的,所以它需要是可靠的。我们所做的只是将数据读入RAM。我们不做交易。我们没有做任何类似的事情。只是,我们把一堆数据拉到内存中,以便我们能够解决这个问题。 为什么我们甚至需要一个服务器?为什么我不能直接从磁盘驱动器上提取这些数据?这样一来,如果电脑足够健康,它完全可以运行我们的应用程序,我们就不会有依赖关系而导致我们失败,我四处寻找,没有SQL数据库引擎可以做到这一点,和我一起工作的一个人说,"理查德,你为什么不直接写一个?" "好吧,我试一试。" 我没有马上这么做,但后来,这是一个资金中断的问题。那是在2000年,如果我没记错的话,纽特-金里奇和比尔-克林顿正在进行某种争吵,所以所有的政府合同都被关闭了,所以我有几个月没有工作,我想,"好吧,我现在就写那个数据库引擎"。 - **06:24** - [Building SQLite V1](https://corecursive.com/066-sqlite-with-richard-hipp/#building-sqlite-v1) **Adam: **This is the year 2000. Wikipedia didn’t exist yet. People with internet were mainly using dial-up, and only 1% of US households had broadband internet. You couldn’t just Google how to build a database and get pointed in the right direction, but Richard had a plan based on his previous experience building compilers. **Richard: **If we think about each SQL statement as a program, my task is to take that program and compile it into some sort of executable code, so I wrote a byte code engine that would actually run a query and then I wrote a compiler that would translate SQL into that byte code and voila, SQLite was born. It wasn’t really used for that project that I was working on, because, well, that one was shut down at the time, but it started back up later, and we incorporated it into that project for testing purposes because the customer’s insisting on Informix, so that’s fine, but Informix is a real hassle to use for development. For development purposes, we would use my engine just for testing and whatnot, but it was never an official part of the project, but I put it out there on the internet and other people started picking it up. I remember, this was before Twitter or anything like that, but there was net news back then, and [inaudible 00:07:42] somebody put a posting [inaudible 00:07:43], was like, “Wow, I’ve got an SQL database running on my Palm Pilot.” I’m not kidding. It really attracted a lot of attention, and that encouraged me to work on it. - **07:54** - [Motorola Phones](https://corecursive.com/066-sqlite-with-richard-hipp/#motorola-phones) - **09:40** - [America Online Phones](https://corecursive.com/066-sqlite-with-richard-hipp/#america-online-phones) - **11:12** - [Symbian OS and Nokia](https://corecursive.com/066-sqlite-with-richard-hipp/#symbian-os-and-nokia) - **13:01** - [The Bus Factor and the Consortium](https://corecursive.com/066-sqlite-with-richard-hipp/#the-bus-factor-and-the-consortium) **Richard:** At this point, we were really into this, and I was kind of doing this full time, but they came to us and said, “Look, we need you to increase the bus factor.” The bus factor means, the number of people who have to be hit by a bus in order to stop all development work, and they felt like the bus factor at SQLite was too … This was their words. They wanted us to start the SQLite Consortium, which was a way of funding project and getting more people involved to guarantee that it was going to be available long term, so we started this big thing and I came up with a bunch of ideas, and it was this crazy thing where all the Consortium members had voting rights, and it was this big thing. Somehow or another, and I don’t know how this happened, Mitchell Baker, she’s the woman who runs the Mozilla Foundation, she got wind of this and called me up, says, “Richard, you’re doing this all wrong. Let me tell you how to set up a consortium.” She laid down the law, says, “Look, the developers have to be in control. Their decision is final. No voting rights on what gets to go into it. The companies that are using, they get the honor of contributing money, but you make all the decisions.” She was very adamant about this and she laid out everything. She’s a lawyer. 在这一点上,我们真的很投入,我也有点全职做这个,但他们来找我们说,"听着,我们需要你增加总线系数。" 公交车系数的意思是,必须有多少人被公交车撞倒才能停止所有的开发工作,他们觉得SQLite的公交车系数太......这是他们的话。他们希望我们成立SQLite联盟,这是一种资助项目的方式,让更多的人参与进来,以保证项目可以长期使用,所以我们开始了这个大事情,我想出了一堆想法,这是一个疯狂的事情,所有的联盟成员都有投票权,这是一个大事情。 不知怎的,我不知道这是怎么发生的,米切尔-贝克,她是管理Mozilla基金会的女人,她得到了这个消息,给我打电话,说,"理查德,你这样做是错误的。让我告诉你如何建立一个财团。" 她制定了法律,说:"听着,开发者必须控制住自己。他们的决定是最终的。没有投票权的东西可以进入。使用的公司,他们得到了出钱的荣誉,但你做所有的决定。" 她对这一点非常坚持,她把一切都摆出来了。她是个律师。 - **15:11** - [Enter Android](https://corecursive.com/066-sqlite-with-richard-hipp/#enter-android) Richard:This was back in 2005 or so, and we were in meetings with Android, and this was before Android was a thing. This was before iPhone, and I was in Mt. View and we were working with a fella, and they had a prototype of their Android phone, and this was before iPhone, so back then, the phones, they had the full QWERTY keyboard at the bottom and a smaller window up on top, like a Blackberry, but we were debugging something with SQLite and we were plugging into the phone and we were running the debugger on a workstation which was pretty amazing. Nobody else could do that, but we had the phone in the debugger and the phone rings, and he looks at it and he says, “Oh, this is my wife. I have to take this call, excuse me.” Richard:那是在2005年左右,我们正在和安卓系统开会,那时候安卓系统还没有出现。那是在iPhone之前,我在Mt.View,我们和一个人一起工作,他们有一个安卓手机的原型,那是在iPhone之前,所以那时的手机,底部有完整的QWERTY键盘,顶部有一个较小的窗口,像黑莓一样,但我们正在用SQLite调试一些东西,我们插入手机,我们在一个工作站上运行调试器,这是非常惊人的。没有人能够做到这一点,但是我们把电话放在调试器中,电话响了,他看了看,说:"哦,这是我的妻子。我必须接这个电话,对不起。" - **17:05** - [Guys, This Is Important](https://corecursive.com/066-sqlite-with-richard-hipp/#guys-this-is-important) - **18:18** - [Testing and Aviation Standards](https://corecursive.com/066-sqlite-with-richard-hipp/#testing-and-aviation-standards) **Richard**: We were going around boasting to everybody naively that SQLite didn’t have any bugs in it, or no serious bugs, but Android definitely proved us wrong. Look, I used to think that I could write software with no bugs in it. It’s amazing how many bugs will crop up when your software suddenly gets shipped on millions of devices. Richard:我们曾天真地对每个人吹嘘说SQLite没有任何bug,或者说没有严重的bug,但Android绝对证明我们错了。听着,我曾经认为,我可以写出没有bug的软件。当你的软件突然被运送到数以百万计的设备上时,竟然会出现这么多的bug。 **Richard: **It is truly amazing. They were getting crashes constantly, and about that same time or slightly before them, I’d been doing some work for Rockwell Collins, an avionics manufacturer, Rockwell Collins, and they introduced me to this concept of DO-178B. It’s a quality standard for safety-critical aviation products, and unlike so many quality standards, this one’s actually readable. Now, it does have a lot of bureaucratic stuff in it, but you can actually buy a copy of this. You do have to buy it. It’s a couple hundred dollars, but it’s a reasonably thin volume and you can read through it, and with sufficient study you can understand what they’re talking about, so I did that, and I actually started following some of their processes, and one of the key things that they push is, they want 100% MCDC test coverage. That’s modified condition decision coverage of the code. Your tests have to cause each branch operation in the resulting binary code to be taken and to fall through at least once. 理查德:这真的很令人吃惊。他们不断地发生坠机事件,大约在同一时间或稍早于他们,我一直在为罗克韦尔柯林斯公司做一些工作,这是一家航空电子设备制造商,罗克韦尔柯林斯公司,他们向我介绍了DO-178B这一概念。这是一个用于安全关键型航空产品的质量标准,与许多质量标准不同,这个标准实际上是可读的。现在,它确实有很多官僚主义的东西在里面,但你实际上可以买到一份这个的副本。你必须要买它。它有几百美元,但它是一本相当薄的书,你可以通读它,通过充分的学习,你可以理解他们在谈论什么,所以我这样做了,而且我实际上开始遵循他们的一些流程,他们推动的关键事情之一是,他们想要100%的MCDC测试覆盖。 这就是代码的修改条件决定覆盖率。你的测试必须使所产生的二进制代码中的每个分支操作都被采取,并且至少有一次失败。 **Richard:** At the machine code level. Yeah. Actually, MCDC’s a little stricter than that. Let’s not dwell on the details, but I had this idea, I’m going to write tests to bring SQLite up to the quality of 100% MCDC, and that took a year of 60 hour weeks. That was hard, hard work. I was putting in 12 hour days every single day. I was just getting so tired of this because with this sort of thing, it’s the old joke of, you get 95% of the functionality with the first 95% of your budget, and the last 5% on the second 95% of your budget. It’s kind of the same thing. It’s pretty easy to get up to 90 or 95% test coverage. Getting that last 5% is really, really hard and it took about a year for me to get there, but once we got to that point, **we stopped getting bug reports from Android.** **理查德:**在机器代码层面。是的。实际上,MCDC比这更严格一些。我们不要纠结于细节,但我有一个想法,我要写测试来使SQLite达到100%的MCDC的质量,这花了一年的时间,每周60小时。那是艰苦的工作。我每天都要工作12个小时。我只是对这种事情感到非常厌倦,因为对于这种事情,就像一个老笑话,你用前95%的预算获得95%的功能,而用后95%的预算获得最后的5%。这也是同样的事情。要达到90%或95%的测试覆盖率是很容易的。获得最后的5%是非常非常困难的,我花了大约一年的时间才达到这一点,但是一旦我们达到这一点,我们就不再收到来自Android的错误报告。 **Richard:**Yeah. IT just worked from there on out. It made a huge, huge difference. We just didn’t really have any bugs for the next eight or nine years. - **21:29** - [Billions of Tests](https://corecursive.com/066-sqlite-with-richard-hipp/#billions-of-tests) 数十亿次的测试 **Richard:** Right. We still maintain the first one, the TCL tests. They’re still maintained. They’re still out there in the public. They’re part of the source tree. Anybody can download the source code and run my test and [inaudible 00:21:55] run all those. They don’t provide 100% test coverage but they do test all the features very thoroughly. The 100% MCD tests, that’s called TH3. That’s proprietary. I had the idea that we would sell those tests to avionics manufacturers and make money that way. We’ve sold exactly zero copies of that so that didn’t really work out. It did work out really well for us in that it keeps our product really solid and it enables us to turn around new features and new bug fixes very fast. How do you count tests? We’ll have a test case but it’ll be parametrized, so that one test case might run 100, 1,000, 100,000 tests, just by looping, by changing one of the parameters. For a typical release, we’ll do billions of tests, but we have, I think it’s on the order of 100,000 distinct test cases. **Adam:** 100,000 distinct test cases, and then they’re parametrized, so then, how many … **Richard:** Yes, so we’ll do billions of tests. Adam: 10万个不同的测试案例,然后它们被参数化,那么,有多少...... Richard: 是的,所以我们要做几十亿次的测试。 **Richard:**No, but we intentionally test on different operating systems. I’ve got some old equipment around here, because these days, all CPUs are little endian, Intel by order, but it wasn’t so long ago that there was a lot of big endian CPUs around. I’ve got a PowerPC iBook up here that we run tests one. We make sure that SQLite works correctly on a big endian platform. We test on 32-bit platforms, test on ARM. We test on Intel chips. We test on 64-bit platforms. We test on Windows and Linux and Mac, OpenBSD, so we test on as many different platforms, as many different operating systems as we can, but we also have lots of different test suites that we run, but we’ve got the original TCL tests. We’ve got TH3. We’ve got the custom fuzzer stuff that are running constantly. We’ve got a thing called SQL logic test. Shane Harrelson did this for us about 10 years ago. He came up with this huge corpus of SQL statements, and he ran them against every database engine that he could get his hands on. We wanted to make sure everybody got the same answer, and he managed to segfault every single database engine he tried, including SQLite, except for Postgres. Postgres always ran and gave the correct answer. We were never able to find a fault in that. The Postgres people tell me that we just weren’t trying hard enough. It is possible to fault Postgres, but we were very impressed. We crashed Oracle, including commercial versions of Oracle. We crashed DB2. Anything we could get our hands on, we tried it and we managed to crash it, but the point was that we wanted to make sure that SQLite got the same answers for all of these queries, or equivalent answers, because a lot of these queries, they’re indeterminate and the rows might come out in a different order because you [crosstalk 00:25:10] order by clause, so we wanted to make sure that all the database engines got equivalent answers. Mostly, we wanted to make sure that SQLite was getting the same answers everybody else is. That’s another test suite, and then we have lots of smaller ones, as well. Between them all, it’s a lot of testing code, and it takes a long time to run. - **25:30** - [Building From First Principles](https://corecursive.com/066-sqlite-with-richard-hipp/#building-from-first-principles) 从第一原理出发进行构建 **Adam:** It’s these tests that allow SQLite to continue improving and evolving. They let Richard be confident in each release, even if large parts of the code base change, and large parts do occasionally get rewritten, as improved ways to structure things are discovered. Remember, Richard built SQLite to run first principles. **Richard:** Origonally, when I set out to write it, I went around looking, is there a reference on how to write an SQL database engine, I found nothing, and so I just had to kind of invent it myself, so it was a completely independent mission. Most of the theory was happening at MIT and Harvard up in Cambridge, or down at Berkeley, but if you didn’t go to one of those three schools, you didn’t even know this body of theory existed, and there wasn’t a real good way to find it. It’s curious, though, if you go back and look at the volcano model used by Postgres and the byte code model used to be SQLite, we converged on all the same ideas. They start out very differently at the top but we converge in all the same areas of how to make it go faster, so I think that that’s kind of a validation in theory. Two independent lines of development came up with the same answer. I had never heard of, for example, a covering index. I was invited to fly to a conference, it was a PHP conference in Germany somewhere, because PHP had integrated SQLite into the project. They wanted me to talk there, so I went over and I was at the conference, but David Axmark was at that conference, as well. He’s one of the original MySQL people. David was giving a talk and he explained about how MySQL did covering indexes. I thought, “Wow, that’s a really clever idea.” A covering index is when you have an index and it has multiple columns in the index and you’re doing a query on just the first couple of columns in the index and the answer you want is in the remaining columns in the index. When that happens, the database engine can use just the index. It never has to refer to the original table, and that makes things go faster if it only has to look up one thing. **Adam:** It becomes like a key value store, but just on the index. **Richard:** Right, right, so, on the fly home, on a Delta Airlines flight, it was not a crowded flight. I had the whole row. I spread out. I opened my laptop and I implemented covering indexes for SQLite mid-Atlantic. **Adam:** That’s awesome. - **28:05** - [B-Trees and the Art of Computer Programming](https://corecursive.com/066-sqlite-with-richard-hipp/#b-trees-and-the-art-of-computer-programming) - **30:02** - [Freedom to Build It Yourself](https://corecursive.com/066-sqlite-with-richard-hipp/#freedom-to-build-it-yourself) 自己建造的自由 **Adam:** Building your own random number generator, starting from an algorithm description in The Art of Computer Programming that you literally have on the shelf behind you in your office, it seems like such a different way to work than I’m used to. SQLite has basically no dependencies that Richard didn’t build himself, except the C compiler and a couple of things from libc. He even built his own source control system and his own bug tracker. What this gives Richard is freedom. 亚当:建立自己的随机数生成器,从《计算机编程艺术》中的算法描述开始,你的办公室后面的架子上就有这个算法,这似乎是一种与我习惯的不同的工作方式。除了C语言编译器和libc中的一些东西,SQLite基本上没有Richard自己建立的依赖性。他甚至建立了自己的源代码控制系统和自己的错误跟踪器。这给了Richard很大的自由。 **Richard: **Have you ever thought about the word freedom, what that means? Freedom means taking care of yourself. People go backpacking or stuff, they go on these long hikes, backpacking, where they carry everything they need on their back and they talk about how freeing that is because they are taking care of themselves. That’s what freedom means, and so, when you write the whole thing yourself, there’s a certain element of freedom in that, because you’re not tied to somebody else. You’re not dependent on different vendor providing you something. Suppose I had elected to go with Berkeley DB as the storage engine for SQLite version two. 理查德:你有没有想过自由这个词,这意味着什么?自由意味着要照顾好自己。人们去背包旅行或其他东西,他们去长途跋涉,背包旅行,他们把所有需要的东西都背在身上,他们谈论那是多么的自由,因为他们在照顾自己。这就是自由的含义,所以,当你自己写整个东西时,有某种自由的元素在里面,因为你不被别人束缚。你不依赖于不同的供应商为你提供的东西。假设我选择使用Berkeley DB作为SQLite第二版的存储引擎。 - **32:18** - [Building Fossil](https://corecursive.com/066-sqlite-with-richard-hipp/#building-fossil) I looked at Git, I looked at Mercurial, and I looked at my requirements and I thought, “You know what? I’m just going to write my own,” so I wrote my own version control system, which is now a project unto itself, and that worked out very, very well, because think, Linus Torvalds wrote Git to support the Linux kernel, and it is perfectly designed to serve the needs of the Linux kernel development community. If you’re working on the Linux kernel, Git is absolutely the perfect version control system. 我看了看Git,我看了看Mercurial,我看了看我的需求,我想,"你知道吗?所以我写了我自己的版本控制系统,现在它已经是一个独立的项目了,而且效果非常非常好,因为想想看,Linus Torvalds写Git是为了支持Linux内核,它被完美地设计用来满足Linux内核开发社区的需求。如果你正在研究Linux内核,Git绝对是一个完美的版本控制系统。 I’m going to write my own mail server. I was making notes on that even as we were setting up this call. That’s a big problem, and that’s at least as difficult if not more difficult than writing a database engine, but I don’t want to be beholden to Gmail. I don’t want them controlling my destiny. I don’t want them controlling the record of all of my conversations. I want to control that myself, and so I’m going to go through a lot of pain and a lot of work and a lot of effort to come up with some solution that I can control myself. I can go out and lease a virtual machine out there in the cloud and run it myself and not depend on a third party to control my email. 我打算写我自己的邮件服务器。甚至在我们建立这个电话的时候,我就在做这方面的笔记。这是一个大问题,如果不是比写一个数据库引擎更难的话,那至少也是同样的困难,但我不想受制于Gmail。我不想让他们控制我的命运。我不想让他们控制我所有的对话记录。我想自己控制这些,所以我打算经历很多痛苦,做很多工作,花很多精力,想出一些我可以自己控制的解决方案。我可以出去在云端租赁一台虚拟机,自己运行它,而不是依赖第三方来控制我的电子邮件。 **If you want to be free, that means doing things yourself.** - **33:31** - [Being Self Sufficient](https://corecursive.com/066-sqlite-with-richard-hipp/#being-self-sufficient) 自给自足 - **37:30** - [Advice for Others](https://corecursive.com/066-sqlite-with-richard-hipp/#advice-for-others) **Richard:** I had this crazy idea that I’m going to build a database engine that does not have a server, that talks directly to disk, and ignores the data types, and if you asked any of the experts of the day, they would say, “That’s impossible. That will never work. That’s a stupid idea.” Fortunately, I didn’t know any experts and so I did it anyway, so this sort of thing happens. I think, maybe, just don’t listen to the experts too much and do what makes sense. **Solve your problem.** - **38:03** - [Outro](https://corecursive.com/066-sqlite-with-richard-hipp/#outro) ### Kubernetes Networking Model Docker注重资源隔离 K8s注重服务网络 #### Network Model ##### Container-to-Container ##### Pod-to-Pod ![image-20210704162945386](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/PicGo/image-20210704162945386.png) ![image-20210704163052770](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/PicGo/image-20210704163052770.png) ![image-20210704165625219](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/PicGo/image-20210704165625219.png) Kube-Proxy Kube-Proxy is a network proxy that runs on each node in your cluster. K8s DNS Used for service discovery FQDN: Fully qualified domain name > sometimes also referred to as an absolute domain name, is a domain name that specifies its exact location in the tree hierarchy of the Domain Name System. It specifies all domain levels, including the top-level domain and the root zone. CNI: Container Network Interface ##### Internet-to-Service ![image-20210704171028595](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/PicGo/image-20210704171028595.png) ### Sledge: Serverless + WASM Runtime #### WASM - JavaScript - If your web page doesn't load with 3 seconds, 40% of your visitors will leave! - Glue/Interpreted language. - Dynamic type/GC - Asm.js - 2021 Mozilla engineer LLVM(Low Level Virtual Machine) - Subset of JavaScript - No GC(Typed Array) ![image-20210704171516689](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/PicGo/image-20210704171516689.png) WASM: 字节码规范,编译规范。 - Compilation target - In/Outsider browser - 4 Basic types(i32/i64 f32/64) - Table - Linear Address(64 KB/Page) ### The Mathematical Beauty of Simplicity 原文:[The Mathematical Beauty of Simplicity](https://waldootis.medium.com/the-mathematical-beauty-of-simplicity-781c89ea2136) laws of nature is [the law of the least rate of energy expenditure](https://agupubs.onlinelibrary.wiley.com/doi/abs/10.1029/WR007i002p00311). Thus, for example, the light emitted from point A chooses the path that requires the least amount of energy among the infinite number of routes to go to point B, which is often also the fastest. 自然规律是能量消耗最小的规律。因此,举例来说,从A点发出的光在无限多的路线中选择需要最少能量的路线去B点,这往往也是最快的。 This least energy expenditure law of nature is often encountered in physics. Our aesthetic perception stems from nature and its laws (where else could it be?!). The law of least energy expenditure also applies in aesthetics. We often find beauty in [simplicity](https://en.wikipedia.org/wiki/Simplicity). 这种自然界的最小能量消耗法则在物理学中经常遇到。我们的审美感知源于自然界及其规律(还能是哪里呢!)。最小能量消耗定律在美学中也适用。我们经常在简单中发现美。 It is not easy to achieve simplicity and beauty. If it was, everyone could be an artist. [Picasso](https://en.wikipedia.org/wiki/Pablo_Picasso) has a series of lithographs, [The Bull](https://www.artyfactory.com/art_appreciation/animals_in_art/pablo_picasso.htm). Successively, all was done within a few days. In the first lithography, we see a realistic bull with all the details. The second lithography has less detail, and there are four-five lines left on the last lithography. This last lithography is so simple that it makes you say, “I could do it too,” like most people do when they see one of Picasso’s “simple” paintings. I understand those people very well, and I even think they are correct, and in these words, they say with childish naivety. 要实现简单和美丽是不容易的。如果是这样,每个人都可以成为艺术家。毕加索有一系列的石版画《公牛》。相继在几天内全部完成。在第一张石版画中,我们看到的是一只逼真的公牛,所有的细节都有。第二张石版画的细节较少,最后一张石版画上还剩下四五条线。这幅最后的石版画是如此简单,以至于让你说:"我也能做到。"就像大多数人看到毕加索的一幅 "简单 "的画时那样。我非常理解这些人,我甚至认为他们是正确的,在这些话中,他们带着幼稚的天真说。 ![image-20210704174650394](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/PicGo/image-20210704174650394.png) With years of experience and undoubted genius, Picasso can reach simplicity in a day or two. But, on the other hand, we, mortals, have to work hard to get to it. We need to spend a lot of energy to reach the “least energy.” Below you can find a good example. Take a look at the figure below. Think of this ABCDE pentagon as a room, which is a strange place with five edges… But this room has a feature. ![img](https://miro.medium.com/max/700/1*E6gZSk4QNThOOcS86rQ0Bw.jpeg) ![img](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/PicGo/1*QUATvCqoAR8pYYdDEHxDMA.jpeg) ![img](https://miro.medium.com/max/700/1*o3pjxH68FYq7w_-7QL71CQ.jpeg) ![img](https://miro.medium.com/max/700/1*BITGvYUq3q6V1Il3qoFfQA.jpeg) ![img](https://miro.medium.com/max/700/1*8C_WdWMwruG0kov2l6GBzQ.jpeg) ### APP 开发技术该如何选型 ? [APP 开发技术该如何选型 ?](https://www.helloworld.net/p/6989645798) ![APP 开发技术该如何选型 ?](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/PicGo/804b45e87f781a36445f6a1c70b3465e.png) 在这里就不讨论原生APP的优点了,想必大家都知道。主要围绕缺点来说 1. 需要 开发 两套 代码 `Android` 和 `IOS` 2. 旧版本出现 `bug` 无法更新修改,必须用户 下载 更新 3. 发版审核时间长,无法随时更新 Web APP ``` 优点 ``` 1. 入门简单,成本低 (前端三件套) 2. 可以同步更新 3. 可以跨平台 ``` 缺点 ``` 1. 不能直接访问设备硬件和离线存储,功能受限( 相机,蓝牙…) 2. 音视频体验不好 ------ 混合APP ``` 优点 ``` 1. 开发效率高 2. 更新和部署方便,不需要审核,只需要在服务器端部署 3. 代码维护方便,版本更新快,成本低 ``` 缺点 ``` 1. 需要了解 `原生开发` 才能更好的开发 `H5` 。 2. 需要熟知 `原生开发` 与 `H5` 的各种通信和兼容性问题。 ### The Terrifying Results of a New AI Study [The Terrifying Results of a New AI Study](https://medium.com/predict/the-terrifying-results-of-a-new-ai-study-7914233b7b9) I am haunted by a story. [It’s a story only a handful of paragraphs long](https://www.roma1.infn.it/~anzel/answer.html), written by a man in the 50’s regarding a superintelligent cybernetics machine. In its sparse half a page lengthlongitud the story introduces us to a powerful computer — an accumulation of billions and billions of smaller computers finally connected at the moment a man named Dwar Ev throws a switch. It is mankind’s first interaction with this new cyber-entity. After a moment a question is presented to the machine: “Is there a God?” With no hesitation whatsoever, with no sound of clicking or static or electrical crackling, the answer comes from the computer’s voice. “Yes, now there is a God.” Following that ominous introduction the computerel computadora intelligence fuses the switch and prevents itself from ever being shut down. We are even witness to what may be the computer’s first murder of many. 我被一个故事困扰着。这是一个只有几段的故事,由一个50年代的人写的,关于一个超级智能的控制论机器。在其稀疏的半页篇幅中,故事向我们介绍了一台强大的计算机--由数十亿和数十亿台较小的计算机累积而成,最终在一个名为Dwar Ev的人抛出开关的那一刻连接起来。这是人类与这个新的网络实体的第一次互动。过了一会儿,一个问题被提交给机器。"有上帝吗?" 没有任何的犹豫,没有任何的点击声、静电声或电击声,答案从计算机的声音中传出。"是的,现在有一个上帝。" 在这个不祥的介绍之后,计算机的智能融合了开关,并防止自己永远被关闭。我们甚至目睹了可能是电脑的第一次谋杀。 > Dwan Ev ceremoniously soldered the final connection with gold. The eyes of a dozen television cameras watched him and the subether bore throughout the universe a dozen pictures of what he was doing. > He straightened and nodded to Dwar Reyn, then moved to a position beside the switch that would complete the contact when he threw it. The switch that would connect, all at once, all of the monster computing machines of all the populated planets in the universe -- ninety-six billion planets -- into the supercircuit that would connect them all into one supercalculator, one cybernetics machine that would combine all the knowledge of all the galaxies. > Dwar Reyn spoke briefly to the watching and listening trillions. Then after a moment's silence he said, "Now, Dwar Ev." > Dwar Ev threw the switch. There was a mighty hum, the surge of power from ninety-six billion planets. Lights flashed and quieted along the miles-long panel. > Dwar Ev stepped back and drew a deep breath. "The honor of asking the first question is yours, Dwar Reyn." > "Thank you," said Dwar Reyn. "It shall be a question which no single cybernetics machinemáquina has been able to answer." > He turned to face the machine. "Is there a God?" > The mighty voice answered without hesitation, without the clicking of a single relay. > "Yes, *now* there is a God." > Sudden fear flashed on the face of Dwar Ev. He leaped to grab the switch. > A bolt of lightning from the cloudless sky struck him down and fused the switch shut. ### How to Exercise Every Inch of Your Brain and Sharpen Your Memory [How to Exercise Every Inch of Your Brain and Sharpen Your Memory](https://medium.com/mind-cafe/how-to-exercise-every-inch-of-your-brain-and-sharpen-your-memory-3f6257267123) > 运动,冥想,3d游戏,数独,高尔夫,Intensive learning To fully reap the benefits of Neuroplasticity, Dr. Amen suggests we work on five different brain areas: the prefrontal cortex (PFC); the temporal, parietal, and occipital lobes; and the cerebellum. Here’s how: 为了充分获得神经可塑性的好处,阿门博士建议我们在五个不同的大脑区域工作:前额皮层(PFC);颞叶、顶叶和枕叶;以及小脑。具体方法如下。 #### The Prefrontal Cortex: The Brain’s CEO The brain has four main regions or lobes: frontal, temporal, parietal, and occipital. The last two perceive our surroundings, whereas the first two — where the prefrontal cortex is located — integrate and analyze the sensory information before making decisions. According to Dr. Amen, the prefrontal cortex is the brain’s CEO as it “enables us to learn from our mistakes and make plans.” When it’s healthy, we’re organized, goal-oriented, thoughtful, empathetic, and emotionally intelligent. We avoid saying or doing idiotic things. When it deteriorates, though, impulsivity, disorganization, poor time management, lack of empathy, among other unwanted problems, arise. 大脑有四个主要区域或脑叶:额叶、颞叶、顶叶和枕叶。后两个区域感知我们的周围环境,而前两个区域--前额叶皮层所在的区域--在做决定之前整合和分析感官信息。 根据阿门博士的说法,前额叶皮层是大脑的CEO,因为它 "使我们能够从错误中学习并制定计划"。当它健康时,我们有组织,以目标为导向,深思熟虑,有同情心,有情感上的智慧。我们避免说或做愚蠢的事情。 然而,当它恶化时,就会出现冲动、无组织、时间管理不善、缺乏同情心以及其他不必要的问题。 ##### How to exercise it: - Language games such as Scrabble and Boggle. - Crossword puzzles. - Speech and debate classes or any other public speaking activities. - Strategy games such as Risk, chess, and Catan. - Prayer and meditation. “It may be the most powerful prefrontal cortex booster of all. It improves focus, executive function, judgment, and impulse control.” - Weight training combined with aerobic activity (brisk walking). #### The Temporal Lobes: The Brain’s Memory Center The temporal lobes have a crucial role when it comes to memories. They contain the hippocampi, two seahorse-shaped structures that house the stem cells responsible for producing new neurons. According to research cited in Dr. Amen’s book, the hippocampi can produce up to 700 new cells every day if we exercise, include omega-3 fatty acids in our diet, engage in mental exercises, and have active social lives. Imagine the potential! However, without a nourishing environment, trouble can befall the temporal lobes, spelling doom. Damage in this area can lead to short and long-term memory problems, reading difficulties, an inability to find the right words in conversation, trouble reading social cues, and mood instability. 颞叶。大脑的记忆中心 当涉及到记忆时,颞叶有一个关键的作用。它们包含海马,两个海马形的结构,容纳了负责产生新神经元的干细胞。 根据阿门博士书中引用的研究,如果我们锻炼身体,在饮食中加入欧米茄-3脂肪酸,从事智力锻炼,并有积极的社交生活,海马体每天可以产生多达700个新细胞。想象一下这种潜力吧! 然而,如果没有一个滋养的环境,麻烦就会降临到颞叶,意味着厄运。这个区域的损害会导致短期和长期的记忆问题,阅读困难,无法在谈话中找到正确的词,难以阅读社会线索,以及情绪不稳定。 ##### How to exercise it: - 3D video games such as Super Mario 3D. - Intensive learning (a degree or a dedicated course). - Memorization of poetry and prose. - Learning to play a new musical instrument, which also stimulates the Prefrontal cortex, parietal lobes, and cerebellum. - Physical exercise. #### The Parietal Lobes: The Brain’s GPS The top, back part of the brain contains the parietal lobes, responsible for our sense of direction and our ability to know right from left. In other words, our GPS. People with trouble in this area often get lost and find it difficult to track objects visually. Worst of all, though, is that people with damaged parietal lobes deny their problems. Those affected don’t recognize the danger they’re in. And how can you solve a problem without acknowledging it first? ##### How to exercise it: - Math games like sudoku. - Juggling. - Golf. “40 hours of training increases gray matter in the parietal and occipital lobes.” - Dancing. - Map reading without a GPS device. #### The Occipital Lobes: The Brain’s Eye If you can read this, then your occipital lobes are fine. Located at the back of the brain, they process visual information. Light, shade, color, and basic shapes are then sorted out. If there were trouble in this area, you would find it hard to discern colors, faces, and anything else in the visual realm. ##### How to exercise it: - Golf. - Optical illusion exercises. - 3D movies. - VR (Virtual Reality) experiences. #### Creating “Whole-Brain Combination Workouts” Dr. Amen’s message is simple: We must exercise every inch of our brain. To do that, select one exercise from each category. For example, learn a new language (prefrontal cortex), solve a sudoku every day (parietal lobes), memorize a poem (temporal lobes), watch 3D movies (occipital lobes), and play table tennis (cerebellum). 阿门博士的信息很简单。我们必须锻炼我们大脑的每一寸肌肤。 要做到这一点,从每个类别中选择一项锻炼。例如,学习一种新的语言(前额皮质),每天解决一个数独(顶叶),背诵一首诗(颞叶),看3D电影(枕叶),打乒乓球(小脑)。 Or — if you’re into efficiency — choose fewer activities that engage several areas of the brain. For example, learn a new musical instrument (prefrontal cortex, temporal lobes, cerebellum, and parietal lobes) and watch 3D movies. 或者--如果你讲究效率--选择较少的活动,让大脑的几个区域参与进来。例如,学习一种新的乐器(前额叶、颞叶、小脑和顶叶)和观看3D电影。 #### **Gut Punch Your Posture** *1: Spend 10 minutes foam rolling each day. 2: Every hour, practice resetting your posture by following the neutral-spine sequence. 3: Punch friends in the gut if they aren’t engaging their abs.* #### **Eat The Right Nutrition** *1: Eat veggies, healthy fats, high quality protein. 2: Reduce sugar 3: Avoid food sensitivities* #### Rewild Yourself With Nature **We have domesticated ourselves and made it taboo to think otherwise.**We are not as fit, resilient, or adaptable and much more prone to chronic disease than our ancestors. If domestication is the problem, then re-wilding is the solution. Daniel outlined four systems for re-wilding our natural nutrition *1: Eat living, wild foods. 2: Drink unprocessed spring water. 3: Breathe air from nature. 4: Expose yourself to sunlight. 5. Go outside.* #### Make Yourself Uncomfortable - Attempt a [Spartan Race](http://www.spartan.com/) - Take a [cold shower](http://impossiblehq.com/cold-shower-therapy-guide) - Try Rejection Therapy. *My experience is here:* [*http://vimeo.com/79453884*](http://vimeo.com/79453884) *(5 min video)* - Contemplate death. Read Seneca or Marcus Aurelius. - Be homeless*? I’m currently doing this, but that’s a story for another day ????* #### Meditate To change where we direct our attention, we need to become aware of our attention. *1: Put yourself in uncomfortable situations to lower your expectations and raise your tolerance. 2: Meditate.* #### **Hear Music, Change Your Brain** Your brain has 100 billion neurons that use electricity to talk to each other. At any moment, millions of neurons are talking at once, which produces a lot of electrical activity. When this activity is measured with an EEG, the result is a wave-like pattern called a brainwave. Brainwaves 101: - Beta (14–30 Hz): **awake**, concentrated, alert. We spend most of the day here. - Alpha (8–14 Hz): **meditative state**, awake but relaxed, twilight state between sleep and waking, improved memory recall. - Theta (4–8 Hz): **light dreaming**, access to unconscious mind. - Delta (0.1–4 Hz): **deep dreamless sleep**, restorative, complete loss of awareness. #### **Show Gratitude** You get the point though: **We can think about the same experience in many different ways.** If we are grateful, we positively change our perspective on the events in our lives. UJ Ramdas presented gratitude as a biohack and offered four techniques to start your daily gratitude practice. - **Gratitude Journal.** At it’s simplest, just write down 3 things you are grateful for each night. *Pro tip*: If you want email reminders, set up a google form (here’s a [template](https://docs.google.com/forms/d/1NBlBzYyjONHoJYsNUTi27bBH-lpWCqoV825hxL74mIs/viewform)) and use [IFTTT](http://ifttt.com/) to email yourself that link (If 10pm, then email me the link to that form). - **Five Minute Journal.** The journal created by UJ. Answer three questions each morning and two before bed. Puts you in the right mindset to start and end your day. (Link [here](http://www.fiveminutejournal.com/)) - **Gratitude Walk.** UJ recommends doing this on your way to work. Be very present and feel gratitude for everything you see and experience during that short walk. Try to *feel* the gratitude in your heart. - **Gratitude Visit.** Write a letter (300 words) of love and gratitude to someone important to you. Set up a time to meet them, then take out the letter and read it to them. UJ says it is extremely transformative. ### 一点收获 - **RN vs Flutter** - RN can use native widgets, or whatever widgets really, and communicate with them through javascript. This way one can use things like maps, ARKit/ARCore, etc. You can also use a lot of existing JS-libraries. The downsides: 1. The javascript engine is kind of slow, since it runs without JIT. 2. Communication with native widgets/libraries is very slow, because of the bridge. So basically you can forget using three.js or something like that to make 60fps physics simulation. It will work, but the performance will be very suboptimal. Flutter runs everything in its own container, and cannot use native widgets inside that container. This makes for very good performance, but things like slippy maps and even webviews will have to be implemented from scratch. It even does not have 3D graphics, and you can forget about ARKit/ARCore. If you are making an app with a simple UI Flutter seems to be the best choice. If you are using lots of widgets, youtube videos, maps etc RN for the time being seems like the best choice.