-
-
Notifications
You must be signed in to change notification settings - Fork 986
Description
Instructions
- Read the issue description below.
- Read the issue comment which follows the description.
- Search the code base for a package having a JavaScript benchmark which needs updating according to the description below.
- 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:
- We add the import
@stdlib/string/format. See the documentation for@stdlib/string/formatfor supported specifiers. - We replace string concatenation
pkg+':ndims='+ndimswith string interpolationformat( '%s:ndims=%d', pkg, ndims ), where%sindicates to insert the package name (a string) and%dindicates to insert the number of dimensions (an integer).
By performing this refactoring, we facilitate
- increased readability of benchmark names when reading benchmark source code.
- easier debugging when encountering malformed benchmark names.
- fine-tuned precision when interpolating numbers.
- 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:
- Study the changes made in commit 086231d, as this commit contains the sorts of changes that we are looking for.
- Ensure you have setup your local development environment by following the contributing guide, including
make install-node-modulesandmake init. - Study the documentation for
@stdlib/string/format. - 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. - 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/formatwhich supports a much greater range of specifiers. - Run JavaScript benchmarks locally using the command
make benchmark BENCHMARKS_FILTER=".*/<package_name>/.*". For example,make benchmark BENCHMARKS_FILTER=".*/blas/ext/base/dfill/.*". - 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).
- Commit your changes.
- Submit a PR updating the JavaScript benchmarks for that package (and only that package).
- 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). - 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:.