npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typescript-code-instruments

v1.0.10

Published

Task logging library for typescript.

Downloads

717

Readme

Typescript Code Instruments

Task logging library for typescript.

This module contains utilities for instrumenting typescript code in anticipation of measurement and debug activities around performance optimization and functionality issues.

Instruments are extra lines of code that we add to a program in order to support fine-grained measurement of performance and functional debug tracing.

Documentation

Proactive + Predictable + Durable Instrumentation

In a typical coding methodology, code instruments are added at the last minute, driven by a (sometimes very urgent) need to debug a particular problem or optimize a particular code execution pathway. The bespoke nature of these on-demand code instruments leads to a variety of log message syntaxes, each of which needs its own analytics script. Moreover, the instrumentation code is treated as disposable, often being removed during the PR review process.

An alternative coding instrumentation methodology is to add the instruments up-front, at low cost, to any execution scope that might have nontrivial performance or functionality impact systematically as a matter of coding practice.

These utilities are designed to support a coding methodology where code instruments are be added proactively, before the moment when they are (perhaps very urgently) needed. The code instruments can convey a variety of data structures inside of a log format that is predictable and consistent. It is this consistency that enables the coding team to develop of a durable kit of log-based analytics scripts that make use of this consistent log format.

Of course, in order for these code instruments to be durable throughout the code development lifecycle, even in production, these utilities also mustminimize any negative impact on readability or performance of the instrumented code.

Features

Each code instrument can be individually activated or deactivated. All code instruments are disabled by default. Python3 bindings are deprecated.

Whenever an instrument notices that the statement scope has been invoked, a 5-character human readable invocation ID is automatically generated. This invocation ID is printed with every log message.

Task

The primary code instrument is a Task. The Task module allows programmers to attach this kind of code instrument to a typescript statement scope such as a method, a function, or a statement block. The instrumented code may be synchronous or async code.

For example, consider this non-instrumented code:

    Promise.all([ 
        ...zone.streams().properties().map(stream => {
            stream.scalar?.pull ? stream.scalar.pull() :
            stream.set?.pull ? stream.set.pull() :
            stream.sequence?.pull ? stream.sequence.pull() :
            stream.map?.pull ? stream.map.pull() : Promise.resolve()
        }),
        ...zone.streams().relations().map(stream => {
            stream.pull ? stream.pull() : Promise.resolve();
        })
    ])

After adding a code instrument, this code looks like this:

    return new Task.Task(`update proposal`).logs(console.log).promises({ peerId }, () => (
        Promise.all([ 
            ...zone.streams().properties().map(stream => {
                stream.scalar?.pull ? stream.scalar.pull() :
                stream.set?.pull ? stream.set.pull() :
                stream.sequence?.pull ? stream.sequence.pull() :
                stream.map?.pull ? stream.map.pull() : Promise.resolve()
            }),
            ...zone.streams().relations().map(stream => {
                stream.pull ? stream.pull() : Promise.resolve();
            })
        ])
    ))