当前位置: 首页 > 编程日记 > 正文

我对Node.js Core的首次贡献中学到了什么

by Yael Hermon

通过Yael Hermon

我对Node.js Core的首次贡献中学到了什么 (What I Learned from My First Contribution To Node.js Core)

A couple of weeks ago my very first PR for Node.js core was merged! A few days later, I decided to tweet about it and share how positive this experience was, hoping to encourage others to contribute as well.

几周前,我对Node.js核心的第一个PR被合并了! 几天后,我决定发布推文并分享这种体验的积极程度,希望能鼓励其他人也做出贡献。

Later, Uri Shaked suggested I share my experience in a short blog post. Uri always has great ideas. Thanks, Uri!

后来, Uri Shaked建议我在一篇简短的博客文章中分享我的经验。 乌里总是有好主意。 谢谢友利

我如何最终获得此PR? (How did I end up with this PR?)

I’m glad you asked. Let me start with a little background. I love Node.js, and contributing to it was actually on my bucket list for a really long time. I never got around to doing it because I always told myself that I didn’t have the time for it, or that I might not be qualified enough, or other lame excuses.

我很高兴你问。 让我从一些背景开始。 我喜欢Node.js,并且对它的贡献实际上已经存在了很长时间。 我从来没有绕过它,因为我总是告诉自己,我没有时间去做,或者我可能没有足够的资格,或者其他la脚的借口。

The plot twist happened when I was working on a talk for a JavaScript-Israel meetup about the V8 Garbage Collector. Benjamin Gruenbaum, a Node.js core collaborator, asked me if I would like him to connect me with V8 engineers to review my slides. Umm…obviously I would.

当我正在为关于V8垃圾收集器JavaScript-以色列聚会进行演讲时,发生了剧情扭曲。 Node.js核心协作者Benjamin Gruenbaum问我是否希望他让我与V8工程师联系以查看我的幻灯片。 嗯…… 显然我会的。

So he did, which turned out pretty awesome. Benji also asked me if I was interested in contributing to Node.js core. Again, I said yes. No more excuses. Stuff just got real.

因此,他做到了,结果真棒。 Benji还问我是否有兴趣为Node.js核心做出贡献。 我再说一次。 别再找借口。 东西变得真实。

搭建环境 (Setting up the environment)

I first had to build Node.js on my machine. It was surprisingly easy, thanks to the great docs Node.js has. Next, I decided to play around and start debugging it.

我首先必须在计算机上构建Node.js。 得益于Node.js 出色的文档 ,这非常容易。 接下来,我决定尝试一下并开始调试它。

I’d be lying if I said it was smooth sailing from the start. The last time I worked with C++ was back in 2012. I was rusty. Moreover, back then I had a completely different environment than I have now. I had a Windows PC with Visual Studio on it, while now I am running VSCode on a Mac.

如果我说从一开始就航行顺利,我会撒谎。 我上一次使用C ++的时间是在2012年。我很生锈。 而且,那时我的环境与现在完全不同。 我有一台装有Visual Studio的Windows PC,而现在我在Mac上运行VSCode。

I love VSCode so I wanted to setup VSCode for this project too. I soon found an extension and configured things to work. For my debugging configuration, I ended up setting up a node debugger and a lldb debugger to attach to the Node process. That worked great.

我喜欢VSCode,所以我也想为此项目设置VSCode。 我很快找到了一个扩展,并配置了某些功能。 对于我的调试配置,我最终设置了一个节点调试器和一个lldb调试器以附加到Node进程。 效果很好。

正在处理实际问题! (Working on an actual issue!)

So Benji connected me with Anna, who’s the Node.js core collaborator who implemented ‘worker_threads’. Benji also pointed me at this issue. I looked at the issue and tried reproducing it with as little code as possible, just to get rid of the noise.

因此,本吉将我与实现了worker_threads的Node.js核心协作者Anna联系 起来 。 本吉也指出我这个问题 。 我研究了这个问题,并尝试使用尽可能少的代码来重现它,以消除噪音。

I struggled with creating a test case that reproduced the issue, since it was caused by a race condition. The code that failed when running inside Node.js wouldn’t fail in my testing environment. Eventually, I found something that failed on all of my runs. Although it might not fail on every machine, or every time, Anna confirmed it was good enough. Next, I started debugging it to see what was actually happening there.

我努力创建一个重现该问题的测试用例,因为它是由竞争状况引起的。 在Node.js中运行时失败的代码在我的测试环境中不会失败。 最终,我发现所有运行都失败了。 尽管它可能不会在每台机器上或每一次机器上都失败,但是Anna确认它已经足够好。 接下来,我开始对其进行调试,以查看实际发生的情况。

If you’ve never heard of ‘worker threads’, that’s probably because they are quite new and are currently in an experimental state. Workers let you create multiple environments running on independent threads. They are useful for performing CPU-intensive JavaScript operations, without blocking the main thread.

如果您从未听说过“工人线程”,那可能是因为它们很新并且目前处于试验状态。 使用工作程序,您可以创建在独立线程上运行的多个环境。 它们对于执行CPU密集型JavaScript操作非常有用,而不会阻塞主线程。

The main thread and the worker thread can communicate with each other through a message channel between them. In addition to this message channel, there is another message channel where internal messages are sent, such as stdout of the worker. When you console.log inside the worker, it arrives to the main thread through this internal message channel and the main thread handles it by pushing it to its stdout stream.

主线程和工作线程可以通过它们之间的消息通道相互通信。 除此消息通道外,还有另一个消息通道,在该消息通道中发送内部消息,例如worker的stdout。 当您在worker内部使用console.log ,它通过此内部消息通道到达主线程,并且主线程通过将其推送到其stdout流来对其进行处理。

The problem was that we were calling the kDispose function in the JS worker class before waiting for all messages from worker’s stdio to be processed by the main thread through the internal message port. So when the worker thread finished, we lost the references for the parent side stdio streams, and a message to the parent could possibly arrive after that.

问题在于,我们在等待工作线程的stdio的所有消息由主线程通过内部消息端口处理之前,在JS worker类中调用了kDispose函数。 因此,当工作线程完成时,我们将丢失父端stdio流的引用,并且在此之后可能会到达父消息。

At first, I tried lots of different approaches to getting this fixed, including setting a promise to be resolved when the message port was done, awaiting it before disposing, and passing JS callbacks to the C++ layer.

最初,我尝试了许多不同的方法来解决此问题,包括设置一个承诺,以便在完成消息端口时解决该承诺,在处理之前等待它,并将JS回调传递给C ++层。

Chatting with Anna about it revealed to me that a drain method existed for the MessagePort and it emitted all its incoming messages synchronously. So in the end, all the messages from it would be processed. In fact, drain was already called for the external MessagePort. How hadn’t I seen this function all this time? ? I added a call to drain also on the internal MessagePort. The fix was that simple.

与Anna聊天时向我透露,MessagePort存在一种耗用方法,并且它同步地发出所有传入的消息。 所以最后,所有来自它的消息都会被处理。 事实上, 排水已经呼吁外部MessagePort。 我怎么一直没有看到这个功能? ? 我还在内部MessagePort上添加了对d rain的调用。 解决方法就是这么简单。

An important thing to remember is — it’s totally fine trying out weird approaches along the way. That’s how you learn. And after debugging lots of worker_threads code, I can say that I know some of its codebase pretty well now :)

要记住的重要一点是–沿途尝试怪异的方法是完全可以的。 那就是你学习的方式。 在调试了很多worker_threads代码之后,我可以说我现在非常了解它的一些代码库:)

Benji and Anna were so welcoming right from the beginning. This was a great experience. I learned a lot from Anna and from the code, which was very challenging. It’s definitely not something I usually deal with in my day-to-day.

Benji和Anna从一开始就非常热情。 这是一次很棒的经历。 我从Anna和代码中学到了很多东西,这非常具有挑战性。 绝对不是我每天通常要处理的事情。

I can’t wait to work on my next issue!

我等不及要处理下一个问题了!

翻译自: https://www.freecodecamp.org/news/what-i-learned-from-my-first-contribution-to-node-js-core-9cdc0e0d5efc/

相关文章:

SHA204A加密芯片配置

1、参考配置文章:http://blog.csdn.net/a5882230/article/details/522148452、可以选slot configuration 1作为密钥区,该区的配置应为:0x81 81,对应的data 0的数据就密钥数据。3、slot configuration的配置有7个参数,其…

[剑指offer] 二叉搜索树的后序遍历序列

二叉搜索树的后序遍历序列 P157 题目:输入一个数组,判断这个数组是不是一个二叉搜索树的后序遍历的结果。 solution:我们知道后序遍历序列的最后一个item是根节点,如果确实是二叉搜索树的后序遍历结果,那么在[0,N-2]中…

HbuilderX中的git的使用 git HbuilderXgit HbuilderX 使用git

【前戏】:得在HubilderX中找到 "工具"->"插件安装" -> "Git插件" 。 【提交代码】:(1)选中该项目的文件,右键,Git提交 (2)填写提交信息、查看…

Swift与Objective-C:与恐龙有关的趋势

by Colin Smith通过科林史密斯 Swift与Objective-C:与恐龙有关的趋势 (Swift vs. Objective-C: The trending up-and-comer vs. the dinosaur) Swift的简短历史 (A short history of Swift) I remember how pivotal it was when Swift was introduced at Apple’s …

我的JavaScript学习笔记

1. 那些老旧的实例可能会在 <script> 标签中使用 type"text/javascript"。现在已经不必这样做了。JavaScript 是所有现代浏览器以及 HTML5 中的默认脚本语言。 2. <head> 或 <body> 中的 JavaScript 您可以在 HTML 文档中放入不限数量的脚本。 …

获取枚举值上的Description特性说明

/// <summary> /// 获取枚举值上的Description特性说明 /// </summary> /// <typeparam name"T">枚举类型</typeparam> /// <param name"obj">枚举值</param> /// <returns></returns> public static str…

微信小程序实时获取用户经纬度

注意&#xff0c;使用这个功能之前手机得先打开位置信息。 现在app.json配置 {"pages": ["pages/map/map","pages/index/index","pages/register/register","pages/logs/logs"],"window": {"backgroundTex…

pwa js_如何在互联网信息亭中实现PWA和Barba.js

pwa jsby Nino Mihovilić由NinoMihovilić 如何在互联网信息亭中实现PWA和Barba.js (How to Implement a PWA and Barba.js into internet kiosks) The project we’ll describe here is an interactive internet kiosk that’s used as an extension for the LikeUs mobile …

Vant 组件库(VUE)的使用 Vant滚动选择器 选择器 传值

在 vue- cli 项目中安装 官方文档链接 npm ( 后面内容需要在控制台终端输入) # 通过 npm 安装 npm i vant -S 自动按需引入组件&#xff1a;babel-plugin-import 是一款 babel 插件&#xff0c;它会在编译过程中将 import 的写法自动转换为按需引入的方式 # 安装插件 npm…

MySQL的安装过程

&#xfeff;&#xfeff;近期对MySQL做了一些研究。曾经主要接触的是SQL SERVER。所以&#xff0c;今天对该安装过程做了一些总结以及使用过程中的一些心得。并分享给大家。记得前面。分享过一篇关于数据库的几种连接方式。而本系列文章。将以对数据库的详细操作为主。 MySQL是…

一个球从100米高度自由落下,每次落地后反弹回原高度的一半; * 再落下,求在第几次之后反弹高度小于0.1米, * 并计算在这一次落地时共经过多少米?...

package com.db2;/*** 一个球从100米高度自由落下&#xff0c;每次落地后反弹回原高度的一半&#xff1b; * 再落下&#xff0c;求在第几次之后反弹高度小于0.1米&#xff0c;* 并计算在这一次落地时共经过多少米&#xff1f;* * author denny**/ public class Demo1 {static …

在遗传算法中出现等式约束_排序算法中的稳定性-等式的处理

在遗传算法中出现等式约束by Onel Harrison通过Onel Harrison 排序算法中的稳定性-等式的处理 (Stability in Sorting Algorithms — A Treatment of Equality) Algorithms are at the heart of computer science. Algorithms used for sorting are some of the most fundamen…

vconsole 调试 查看LOG VUE在手机上调试 手机查看h5的日志

简单介绍下vConsole&#xff1a; vConsole是一个由微信公众平台前端团队研发的web前端开发者面板&#xff0c;可用于展示console日志&#xff0c;方便开发、调试。 使用场景1&#xff0c;在vue-cli 构建的项目中使用&#xff1a; 通过npm安装和使用: npm install vconsole -…

无参数的lambda匿名函数

lambda 语法&#xff1a; lambda [arg1[,arg2,arg3....argN]]:expression 1.单个参数的&#xff1a; g lambda x:x*2 print g(3) 结果是6 2.多个参数的&#xff1a; m lambda x,y,z: (x-y)*z print m(3,1,2) 结果是4 3.无参数 # 使用def定义函数的方法 def true():return Tru…

scrum项目管理_Scrum,用于初创企业(或针对该项目的任何项目)

scrum项目管理Scrum is a lightweight framework designed to help small, close-knit teams of people develop complex products.Scrum是一个轻量级框架&#xff0c;旨在帮助紧密联系的小型团队开发复杂的产品。 Of course, Scrum isn’t just applicable to software proje…

升级Jekyll 3.0

每一次的升级都得又一次折腾一次&#xff0c;jekyll也不例外 从jekyll 2.5.2 升级为jekyll 3.0.1 错误一: jekyll 3.0.1 | Error: Permission denied - bind(2) for 127.0.0.1:4000 端口被占有&#xff0c;打开_config.yml 在最后加上一行 port: 5001 (其它也可)问题解决 错误…

jquery学习(3)--高级选择器

自己手写的学习笔记。常规选择器&#xff1a; /****************学习--高级选择器&#xff08;1&#xff09;****************/---高级选择器&#xff1a;ie7层次选择器&#xff1a;后代选择器 ul li a $(ul li a) 获取追溯到的多个dom对象 ie6子选择器 …

h5 返回上一页并且刷新页面

window.history.go(-1) 和 window.history.back(-1) 都用了&#xff0c;安卓会刷新&#xff0c;IOS系统不刷新&#xff08;IOS会读取浏览器缓存&#xff09; 下面用了一种比较low的方法&#xff0c;但是好歹实现了。。 //home.html localStorage.setItem(homeHref,window.loc…

kotlin中的异常处理_如何使用assertFailsWith在Kotlin中测试异常

kotlin中的异常处理by Daniel Newton丹尼尔牛顿 如何使用assertFailsWith在Kotlin中测试异常 (How to test exceptions in Kotlin with assertFailsWith) I wanted to write this short post to highlight the assertFailsWith function available to Kotlin. This function m…

学习dubbo框架的问题

InputStream &#xff1a; 是所有字节输入流的超类&#xff0c;一般使用它的子类&#xff1a;FileInputStream等&#xff0c;它能输出字节流&#xff1b;InputStreamReader &#xff1a; 是字节流与字符流之间的桥梁&#xff0c;能将字节流输出为字符流&#xff0c;并且能为字节…

Android 控件 之 Menu 菜单

http://www.cnblogs.com/Mrs-cc/archive/2012/07/21/2603042.html 1.OptionsMenu &#xff08;选项菜单&#xff09;用法总结使用方法&#xff1a;方法一&#xff1a;添加菜单项&#xff1a;onCreateOptionsMenu&#xff08;Menu menu&#xff09;中添加menu.add(Menu.NONE,Men…

VUE保存页面的数据,VUE页面显示就执行某个函数,VUE页面隐藏就执行某个函数

用 VUE 默认的 keep-alive 组件实现 保存页面的数据,页面显示就执行某个函数&#xff0c;页面隐藏就执行某个函数实现方式&#xff1a; 1.在路由内设置页面是否需要缓存&#xff1b; 示例代码&#xff1a;&#xff08;在需要的组件里面添加meta 对象&#xff0c;keepAlive属…

npm i和npm_让您的NPM套件包含Jest和Codecov☂️

npm i和npmby Carl-Johan Kihl卡尔约翰基尔(Carl-Johan Kihl) 让您的NPM套件包含Jest和Codecov☂️ (Get your NPM-package covered with Jest and Codecov ☂️) 介绍 (Introduction) Let’s talk about code coverage, and how you can do coverage reports in Jest and Cod…

分页传页数的方法

<!DOCTYPE html><html> <head> <meta charset"UTF-8"> <title></title> </head> <body> <div> <span id"num">1</span> <button id"prev">上一页</button> <…

VUE input唤起键盘 底部固定的标签被顶上去解决办法

通过输入框的失去焦点事件和点击事件&#xff0c;当出现键盘时把绝对定位的底部文字隐藏&#xff0c;失去焦点&#xff08;键盘隐藏的时候&#xff09;显示底部文字 解决代码 <input type"text" class"weui-input" click"input_click" blur…

unity中摄像机的控制---调整摄像机,不让他摔倒

摄像机大部分人都会控制&#xff0c;最明显的就是让他旋转&#xff0c;随着鼠标的左右上下移动而旋转&#xff0c;但是总是会遇到一个问题&#xff0c;就是转着转着就仿佛他自己摔倒了似的&#xff0c;其实就是它本身绕着Z轴旋转了 这样就不是我们想要的结果了 要想解决也简单&…

java正则表达式课程_通过此免费课程学习正则表达式

java正则表达式课程by Beau Carnes通过博卡恩斯 通过此免费课程学习正则表达式 (Learn Regular Expressions with this free course) “Some people, when confronted with a problem, think ‘I know, I’ll use regular expressions.’ Now they have two problems.” -Jami…

Codeforces Round #370 (Div. 2)

A - Memory and Crow 这题我没看题意&#xff0c;看了样例猜了一下就AC了&#xff0c;题目好像还挺复杂的。 #include<bits/stdc.h> using namespace std; int a[100005]; int main() {int n;cin>>n;for(int i1;i<n;i) scanf("%d",&a[i]);for(int…

pat1004. Counting Leaves (30)

1004. Counting Leaves (30) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Each input file contains…

css 引用字体

最近遇到个问题&#xff0c;页面使用的字体要用PingFangSC字体&#xff0c;引入方法如下&#xff1a; 简单介绍下PingFangSC字体&#xff1a; &#xff08;1&#xff09;苹方-简 常规体 font-family: PingFangSC-Regular, sans-serif; &#xff08;2&#xff09;苹方…