Skip to content

Commit

Permalink
improve performance (#175)
Browse files Browse the repository at this point in the history
* improve performance

* Create hungry-peaches-watch.md

* fix

* fix

* update
  • Loading branch information
ota-meshi committed Nov 10, 2023
1 parent 1439eb0 commit 5dae3ea
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 73 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-peaches-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"toml-eslint-parser": patch
---

improve performance
8 changes: 8 additions & 0 deletions .github/workflows/NewOldBenchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
compare_version:
default: latest
description: Versions to compare

jobs:
benchmark:
Expand All @@ -16,6 +21,9 @@ jobs:
run: npm run setup
- name: Install Packages
run: npm install -f
- name: Install target
run: npm install -f toml-eslint-parser@${{ github.event.inputs.compare_version }}
if: ${{ github.event.inputs.compare_version != null }}
- name: Build
run: npm run build
- name: Benchmark
Expand Down
18 changes: 11 additions & 7 deletions benchmark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import * as Benchmark from "benchmark";
import fs from "fs";
import { parseForESLint } from "..";
import { parseForESLint as parseOld } from "../node_modules/toml-eslint-parser";
import { version as oldV } from "../node_modules/toml-eslint-parser/package.json";
import { parse as parseByIarna } from "@iarna/toml";
import { listUpFixtures } from "../tests/src/parser/utils";

const files5m = [...listUpFixtures()]
const files10k = [...listUpFixtures()]
.filter((fixture) => {
return fs.statSync(fixture.inputFileName).size > 10000;
})
Expand Down Expand Up @@ -50,22 +51,25 @@ function onComplete(): void {
}
}

console.log("Benchmarking...");
console.log("Old toml-eslint-parser version:", oldV);

const suite = new Benchmark.Suite("benchmark", { onCycle, onComplete });

for (const no of [1, 2, 3, 4, 5]) {
suite.add(`${no} new toml-eslint-parser`, function () {
files5m.forEach((contents) => {
parseForESLint(contents, {});
files10k.forEach((content) => {
parseForESLint(content, {});
});
});
suite.add(`${no} old toml-eslint-parser`, function () {
files5m.forEach((contents) => {
parseOld(contents, {});
files10k.forEach((content) => {
parseOld(content, {});
});
});
suite.add(`${no} @iarna/toml `, function () {
files5m.forEach((contents) => {
parseByIarna(contents);
files10k.forEach((content) => {
parseByIarna(content);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"nyc": "^15.1.0",
"prettier": "^3.0.0",
"semver": "^7.3.4",
"toml-eslint-parser": "^0.9.0",
"toml-eslint-parser": "^0.6.0",
"ts-node": "^10.0.0",
"typescript": "~5.0.0",
"vue-eslint-parser": "^9.0.0"
Expand Down
7 changes: 0 additions & 7 deletions src/tokenizer/code-point-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ export class CodePointIterator {
return (this.lastCodePoint = cp);
}

public currChar(): string {
const cp = this.lastCodePoint;
if (cp === CodePoint.LINE_FEED) return "\n";
if (cp < 0x10000) return this.text[this.start.offset];
return this.text.slice(this.start.offset, this.end.offset);
}

public *iterateSubCodePoints(): IterableIterator<number> {
let index = this.end.offset;
while (true) {
Expand Down

0 comments on commit 5dae3ea

Please sign in to comment.