Skip to content

[RFC]: use string interpolation in JavaScript benchmarks for the benchmark name (tracking issue) #8647

@kgryte

Description

@kgryte

Instructions

  1. Read the issue description below.
  2. Read the issue comment which follows the description.
  3. Search the code base for a package having a JavaScript benchmark which needs updating according to the description below.
  4. Follow any additional guidance specified in this issue.

Description

This RFC proposes improving JavaScript benchmarks by moving away from string concatenation when specifying the benchmark name.

In short, this RFC seeks to refactor JavaScript benchmarks from, for example,

// ...

bench( pkg+':ndims='+ndims, function benchmark( b ) {
    // ...
});

// ...

to

// ...
var format = require( '@stdlib/string/format' );
// ...

bench( format( '%s:ndims=%d', pkg, ndims ), function benchmark( b ) {
    // ...
});

// ...

This refactoring is demonstrated in commit 086231d.

In particular, notice two things:

  1. We add the import @stdlib/string/format. See the documentation for @stdlib/string/format for supported specifiers.
  2. We replace string concatenation pkg+':ndims='+ndims with string interpolation format( '%s:ndims=%d', pkg, ndims ), where %s indicates to insert the package name (a string) and %d indicates to insert the number of dimensions (an integer).

By performing this refactoring, we facilitate

  1. increased readability of benchmark names when reading benchmark source code.
  2. easier debugging when encountering malformed benchmark names.
  3. fine-tuned precision when interpolating numbers.
  4. a future in which we can lint benchmark names which is not currently possible with the current string interpolation approach.

Steps

Given the relatively widespread practice of using string concatenation in benchmarks, this RFC aims to be an open call for any contributor wanting to contribute to the project to do the following:

  1. Study the changes made in commit 086231d, as this commit contains the sorts of changes that we are looking for.
  2. Ensure you have setup your local development environment by following the contributing guide, including make install-node-modules and make init.
  3. Study the documentation for @stdlib/string/format.
  4. Find a package containing a JavaScript benchmark which performs string concatenation when specifying the benchmark name. A possible global project search could use the regular expression bench\(\s*pkg\s*\+\s*'. From the search results, you should be able to find a package in need of updating.
  5. Update the JavaScript benchmarks for that package, and only that package, to migrate to use string interpolation. JavaScript benchmarks can be found in the benchmarks/ folder of a package (if it exists). We are not interested in refactoring to use template strings. You should use @stdlib/string/format which supports a much greater range of specifiers.
  6. Run JavaScript benchmarks locally using the command make benchmark BENCHMARKS_FILTER=".*/<package_name>/.*". For example, make benchmark BENCHMARKS_FILTER=".*/blas/ext/base/dfill/.*".
  7. Verify that the formatted benchmark names in the benchmark output after refactoring match the benchmark names in the benchmark output prior to refactoring (meaning, verify that everything is formatted correctly and the original names are preserved).
  8. Commit your changes.
  9. Submit a PR updating the JavaScript benchmarks for that package (and only that package).
  10. For the PR title, use the following template "bench: refactor to use string interpolation in <package_name>" where <package_name> is the name of the package you updated (e.g., blas/ext/base/dfill).
  11. In the PR body/description, use the phrase "Resolves a part of ", and not "Resolves " or "Closes ", this issue, as this is a tracking issue and your PR only addresses one package of many needing updating.

Please do NOT make extraneous changes to benchmarks. We are not interested in changing benchmarks wholesale. We are only interested in replacing string concatenation logic with string interpolation when specifying a benchmark name.

Related Issues

None.

Questions

None.

Other

  • If you are interested in working on this RFC, for each pull request, please only update the benchmarks for a single package.
  • As mentioned above, please do NOT make extraneous changes to benchmarks. We are not interested in changing benchmarks wholesale. Nor are we interested in new "creative" changes. We are only interested in replacing string concatenation with string interpolation when specifying a benchmark name. Failure to match the behavior of the existing benchmarks and to respect this guidance will result in your PRs being automatically closed without review.
  • As this is a "Good First Issue", you are strongly encouraged to avoid using AI when authoring your contribution. One of the primary intents of Good First Issues is to help introduce you to stdlib, its development environment, and the contribution process, as documented in the contributing guide. Most new contributors are unfamiliar with stdlib and its conventions, and thus fail to appropriately use LLMs and AI when authoring contributions, most often generating AI slop and leading to wasted time. Don't be one of those people. :) Take the time to manually author your first several PRs, and, once you are intimately familiar with project conventions, you can consider leveraging AI to augment your dev tasks.

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AcceptedRFC feature request which has been accepted.BenchmarksPull requests adding or improving benchmarks for measuring performance.Good First IssueA good first issue for new contributors!JavaScriptIssue involves or relates to JavaScript.RFCRequest for comments. Feature requests and proposed changes.Tracking IssueTracking issue.difficulty: 1Low degree of difficulty. Should be straightforward to implement and/or resolve.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions