-
pprof ↗
Google:
pprof is a tool for visualization and analysis of profiling data.
pprof reads a collection of profiling samples in profile.proto format and generates reports to visualize and help analyze the data. It can generate both text and graphical reports (through the use of the dot visualization package).
Combine with pprof-nodejs to profile Node.js apps with V8 CPU and Heap profilers.
Courtesy: Google Inc. -
Cap’n Web: RPC system for browsers and web servers ↗
Kenton Varda and Steve Faulkner at Cloudflare:
Allow us to introduce Cap’n Web, an RPC protocol and implementation in pure TypeScript.
Cap’n Web is a spiritual sibling to Cap’n Proto, an RPC protocol I (Kenton) created a decade ago, but designed to play nice in the web stack.
No schemas, zero dependencies, 10 kB, bidirectional calling, pass functions by reference, pass objects by reference, promise pipelining, and capability-based security patterns.
Example client:
import { newWebSocketRpcSession } from "capnweb"; // One-line setup. let api = newWebSocketRpcSession("wss://example.com/api"); // Call a method on the server! let result = await api.hello("World"); console.log(result);
Example RPC server:
import { RpcTarget, newWorkersRpcResponse } from "capnweb"; // This is the server implementation. class MyApiServer extends RpcTarget { hello(name) { return `Hello, ${name}!` } } // Standard Workers HTTP handler. export default { fetch(request, env, ctx) { // Parse URL for routing. let url = new URL(request.url); // Serve API at `/api`. if (url.pathname === "/api") { return newWorkersRpcResponse(request, new MyApiServer()); } // You could serve other endpoints here... return new Response("Not found", {status: 404}); } }
One of the more interesting parts of Cap’n Web is how lists are handled:
Often, GraphQL is used to say: “Perform this query, and then, for every result, perform this other query.” For example: “List the user’s friends, and then for each one, fetch their profile photo.” In short, we need an
array.map()
operation that can be performed without adding a round trip. Cap’n Proto, historically, has never supported such a thing. But with Cap’n Web, we’ve solved it.let user = api.authenticate(token); // Get the user's list of friends (an array). let friendsPromise = user.listFriends(); // Do a .map() to annotate each friend record with their photo. // This operates on the *promise* for the friends list, so does not // add a round trip. let friendsWithPhotos = friendsPromise.map(friend => { return {friend, photo: api.getUserPhoto(friend.id))}; } // Await the friends list with attached photos -- one round trip! let results = await friendsWithPhotos;
.map()
is special. It does not send JavaScript code to the server, but it does send something like “code”, restricted to a domain-specific, non-Turing-complete language. The “code” is a list of instructions that the server should carry out for each member of the array.But the application code just specified a JavaScript method. How on Earth could we convert this into the narrow DSL?
The answer is record-replay: On the client side, we execute the callback once, passing in a special placeholder value. The parameter behaves like an RPC promise. However, the callback is required to be synchronous, so it cannot actually await this promise. The only thing it can do is use promise pipelining to make pipelined calls. These calls are intercepted by the implementation and recorded as instructions, which can then be sent to the server, where they can be replayed as needed.
This is one of the most useful parts of GraphQL but so much simpler. The serialization format is JSON which is a big plus for web developers.
-
A New Type of Preacher
“He will love Christ and the souls of men to the point of willingness to die for the glory of the one and the salvation of the other.” More →
-
OpenTelemetry Tracing in 200 lines of code ↗
Developers tend to treat tracing as deep magic, and OpenTelemetry is no exception. OpenTelemetry may be even more mysterious given how many concepts you are exposed to even with beginning examples.
It also doesn’t help that as part of building a mature, battle-tested tracing library, the code itself tends to become more and more cryptic over time, contorting itself to avoid edge-cases, work across many environments, and optimize code paths to avoid impacting performance of its host applications. Auto-instrumentation is particularly prone to inscrutibility as it seeks to auto-magically wrap code that may never have been intended to be wrapped or extended.
It’s no wonder then that most developers approach tracing libraries as unknowable black boxes. We add them to our applications, cross our fingers, and hope they give us useful information when the pager goes off at 2am.
They are likely a lot simpler than you expect! Once you peel back the layers, I find a useful mental model of tracing looks like “fancy logging” combined with “context propagation” a.k.a “passing some IDs around”.
Lots of useful tool mentions like otel-tui which is new to me. And for more fancy context, consider async-provider.
-
force_balance_tags function breaks nested G in SVG ↗
SVG icons with nested
<g>
may be corrupted when displayed in WordPress. This is a 4+ year old bug. The simple workaround is to uncheck “WordPress should correct invalidly nested XHTML automatically” in Settings > Writing.
Follow
Featured Blog Post
-
Starting at Apple
I will help small businesses succeed by building Apple Business Essentials — a product which brings together device management, 24/7 Apple support, and iCloud storage into flexible subscription plans. More →