Code makes the world a better place

[論文] 好像沒有那麼快:WebAssembly vs. Native Code 程式碼效能分析

Paper: Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code
Author: Abhinav Jangda, Bobby Powers, Emery D. Berger, and Arjun Guha, University of Massachusetts Amherst
Source: USENIX ATC 2019


作者們先前開發了 BROWSIX,可以讓 Unix 程式直接轉成 JavaScript 並跑在瀏覽器。BROWSIX 基本上就是把程式碼轉成 JavaScript 並且用 Browser API 來模擬 Unix System Call。此篇作者更進一步,開發 BROWSIX-WASM(fork 自 Emscripten)將程式碼轉成 WebAssembly,一來解決原本 JavaScript 效能不佳問題,同時也能可以拿來和 Native Code 在 SPEC CPU suite of Benchmark 上做效能比較。實驗結果 WebAssembly 在現代瀏覽器(Chrome & Firefox)上慢 Native Code 大約 50%,並深入探討為什麼會這樣。


Continue reading



Continue reading

紅黑樹(Red Black Tree)介紹

紅黑樹是一種特別的資料結構,他具有跟 AVL Tree 一樣可以自動平衡的功能。


  • 每個 node 只有黑與紅
  • Root 必須是黑
  • 每個葉子(leaf)是 NIL 且為黑
  • 如果一個 node 是紅,那他的 child 都會是黑
  • 每一條從 root 到 leaf 的路徑所包含的黑色 node 數量都一樣

遵循這樣的規則,可以確保在增加和刪除節點時,保持著樹的平衡狀態。紅黑數保證當 node 數量是 n 時,他的高度最多不會超過 2log(n+1)

在現實生活中,常常用來實作 set 和 dictionary,C++ 中的 std::setstd::map 背後正是紅黑樹。

Continue reading

Example of Signals by `sigaction` in Unix

Unix 中 processes 之間溝通有很多種,本篇介紹 signal 的簡易使用。可以先閱讀 Beej 的介紹。顧名思義,signal 就是程序發送和接受訊號,例如我們在使用 Shell 的時候,之所以 Ctrl-C 可以中斷程式執行,就是因為 Shell 捕捉到 Ctrl-C 發送的 SIGINT 訊號,知道有一個 interrupt signal,所以將程式中斷。

發送 signal 可以用 sigaction()signal(),不過建議使用 sigaction 因為比較新,詳細差別可以看 Stack Overflow 這篇 「What is the difference between sigaction and signal?」。

如果想觸發 signal,可以用 kill()sigqueue(),差別在於後者僅限 Linux,但後者可以藉由傳送 siginfo 加一些資訊在 signal 中。此外一些 system call 本身也會觸發 signal,例如如果嘗試 send() 到不存在的 socket,就會觸發 SIGPIPE

Continue reading

Use `mmap` to create shared objects

當我們有很多 processes 時,並想用實現 shared memory 處理共用資料時,就可以使用 shared memory,來實作。建立 shared memory 可以使用 mmap 或是 System V shmget,但根據 Stack Overflow 「How to use shared memory with Linux in C」回答,shmget 已經有點過時,mmap 則比較新和彈性。

Shared memory 讓我們可以建立一塊共用的記憶體空間,mmap 會回傳一塊記憶體空間的指標,型別是 void *,如果我們想要放資料進去,可以用 memcpy 將物件、字串或任何東西拷貝進去。我們也可以直接將 void * 轉型成物件指標,這樣就建立 shared object,不同 process 可以直接對 process 存取物件。

Continue reading

Review of “Everything in Rust” of COSCUP 2019

Review of “Everything in Rust” of COSCUP 2019

My experience with Rust Taiwan community in COSCUP 2019

Sunshine, blue sky, and sprinkles of rain — such diverse weather on August 16th-17th echoed the lively atmosphere at NTUST in Taipei, where the COSCUP was held. Participating in the conference, Rust Taiwan community hosted the “Everything in Rust” track with 11 talks, which were relevant to Rust. Speakers came from all over the world, including India, Netherlands, China, Hong Kong, and Taiwan, representing for some of the top influencers in the global Rust community. With more than one thousand attendees in COSCUP, it was the first time for these hundreds of people encountered the efflorescence of the Rust programming language.

Continue reading


這是我在台大的第八個學期,也是最後一個學期了。大四下對多數人而言是輕鬆寫意,學分已經修完沒有畢業壓力,但因為我轉系且一直跑去外系修課,導致自己學分到大四下還沒修滿,為此大四下還有 12 學分要修,幾乎每天都還是要去學校。

Continue reading

Localize the Rust Website to Traditional Chinese

Record Rust Taiwan community’s work of translating the Rust website

I am glad to announce that the Traditional Chinese (正體中文) version of the Rust official website has been launched. Thanks to all contributors in the community. This article records our experience to achieve the work.

Continue reading


2019 年,適逢我國上個世紀偉大國畫家張大千先生 (1899-1983) 一百二十歲誕辰,台北故宮博物院特別開設「巨匠的剪影——張大千特展」。張大千一生充滿傳奇,生平走訪世界各地,各種書畫種類無一不臻妙境。

Continue reading


<風起>是日本知名動畫導演宮崎駿生平最後一部作品,內容以零式艦上戰鬥機設計者堀越二郎的生平作為主軸,穿插小說家堀辰雄的兩篇小說作品《風吹了》和《菜穗子》的劇情。 Continue reading


The Clean Coder 心得、摘要與補充

前陣子把 《The Clean Coder》(中譯: 無瑕的程式碼 番外篇-專業程式設計師的生存之道) 看完,剛好可以回答一個網路上最常看到的問題之一:


Continue reading





Continue reading


Chaos implies a disorder or complex non-linear system. It manifests any little changes could probably result in a massive transformation of the system, such as a butterfly flapping in Brazil could cause a hurricane in Texas, which is well known as the butterfly effect. The traits of chaos are in many fields, including math, physics, atmospheric science, fluid dynamics, ect., which leads Chaos to a vital research topic.

Continue reading

Browsing Websites

Browsing Websites

The technology around us affects us profoundly - emotionally, behaviorally, and cognitively. We could easily spend an enormous span not only to watch videos online but also browse websites on the internet every day. However, have you ever thought about how the sites work and what the mechanism is inside the box?

Continue reading

Revision Control

It’s a late night, and the man is still at the office, being in deep water over the crashed program. Everything goes wrong. He doesn’t even know why the code cannot run as usual. Unfortunately, he has forgotten what he had changed, regardless of the changes, which must be of paramount importance to the incident.

Continue reading


Continue reading