Code makes the world a better place

How to debug Rust via GDB

Introduction

Big open source projects are huge, such as the Servo browser in Rust. I have counted the lines of code for you. There are almost a hundred thousand lines of code in the Servo project. To develop such a big project, knowing how to debug in a right way is very important, since you would like to find the bottleneck in a fast and efficient way.

In this article, I will teach you some tips to use GDB developing and debugging your Rust code and the Servo project. The debug method can be also applied to C/C++ as well.

Continue reading

How to Debug Rust via GDB

Introduction

Big open source projects are huge, such as the Servo browser in Rust. I have counted the lines of code for you: there are almost a hundred thousand lines of code in the Servo project. To develop such a big project, knowing how to debug in the right way is very important, since you want to find the bottleneck quickly and efficiently.

In this article, I will teach you some tips for using GDB to develop and debug your Rust code and the Servo project. The same debugging approach can also be applied to C/C++.

Continue reading

Performance Analysis with perf on Linux (Beginner)

Introduction

With a profiler, we can learn more about how software runs—such as memory usage, CPU cycles, cache misses, I/O time, and more. This information is extremely helpful for locating performance bottlenecks. The ultimate goal of performance analysis is to find what slows the program down and maximize performance.

This post introduces perf on Linux. Using a simple program example, I will demonstrate how to analyze a program with perf, and you will see that using a profiling tool can make it much easier to identify the root cause. This post references Gabriel Krisman Bertaz’s Performance analysis in Linux。

Continue reading

Building a Simple HTTP Server in Elixir

Introduction

Elixir is a dynamic functional programming language designed for building scalable and maintainable systems.

Elixir is built on the Erlang VM, which makes it suitable for systems that require low latency, distribution, and fault tolerance. It is also used for web development, embedded software, data processing, multimedia processing, and more. The article “Game of Phones: History of Erlang and Elixir” explains the background and history of Elixir and is well worth reading.

Elixir is quite fun to write. After writing some Elixir, I realized that JavaScript and Rust have borrowed many concepts from functional programming. So when learning Elixir from scratch, many FP features—such as Pattern Matching and Enumerable—felt familiar because I had encountered them before.

After reading the official language guide, I felt I needed a small project to get more hands-on experience, so I looked into how to build a simple HTTP server with Elixir.

Continue reading

NCTU Observations and Reflections (3): First-Year Master's (Spring) — Fine Arts Club & Research

Preface

Following the previous post, which covered my coursework in the spring semester of my first year, this time I will talk about extracurricular activities and research. My only extracurricular was the Fine Arts Club. Compared with my undergraduate years—interning everywhere, contributing to open-source projects, and participating in communities—this semester felt much simpler. Because I decided to take my master’s program seriously relatively late, I was already behind when it came to exploring directions and finding a topic. Still, this semester I found a research area that genuinely interests me and also settled on a topic, and I began working on it over the summer.

Continue reading

A Comprehensive Guide to Using WebAssembly

1. Introduction

Let’s start with the basics: what is WebAssembly, and why do we need it?

Today, web technology is everywhere. People spend hours online every day, enjoying all kinds of services. More and more applications are moving to the web, and desktop or mobile apps increasingly adopt web-based implementations (Web Apps) or hybrid architectures (Hybrid Apps). In a sense, web technology has taken over the world.

The web runs on JavaScript (JS). As browsers and JS engines have evolved, we seem to have reached a bottleneck for performance optimization. No matter how fast JS becomes, because it is an interpreted language, it reads and compiles code line by line at runtime. This execution model is inevitably slower than compiled languages such as C++.

Then you might ask: why not use compiled languages like C++ directly on the web? Because whether you compile ahead of time or compile in the browser, there are trade-offs. Ahead-of-time compilation typically produces large binaries; shipping those to the browser can waste network transfer time. If you ship source-like representations and compile in the browser, you may still pay a significant compile time before you can run. With JS, the source files are relatively small (so transfer is acceptable), and the browser can compile incrementally as it reads, so earlier compiled parts can start running sooner without making the experience unbearably slow.

Either way, JS performance has limits. People wanted a way to make web applications run faster in browsers, and that is where WebAssembly (WASM) comes in. WASM is a low-level, assembly-like format whose performance can approach native code—similar to what you get from C++ or Rust. In web development, JS and WASM are used together. The basic idea is: keep general application logic in JS, but move compute-heavy parts into precompiled WASM to significantly improve performance. This way, you get both fast startup (JS) and high performance for heavy computation (WASM).

Next, this post introduces how to develop using JS together with WASM.

Continue reading