Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

antlr4ng

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antlr4ng - npm Package Compare versions

Comparing version 2.0.10 to 2.0.11

2

dist/IntStream.d.ts

@@ -194,3 +194,3 @@ /**

*/
const EOF = -1;
const EOF: number;
/**

@@ -197,0 +197,0 @@ * The value returned by {@link IntStream.getSourceName} when the actual name of the

@@ -8,3 +8,3 @@ export declare class BitSet implements Iterable<number> {

*/
constructor(data?: bigint[]);
constructor(data?: number[]);
/**

@@ -11,0 +11,0 @@ * @returns an iterator over all set bits.

@@ -67,3 +67,3 @@ import { CharStream } from "./CharStream.js";

const MIN_USER_TOKEN_TYPE: number;
const EOF = -1;
const EOF: number;
/**

@@ -70,0 +70,0 @@ * All tokens go to the parser (unless skip() is called in that rule)

{
"name": "antlr4ng",
"version": "2.0.10",
"version": "2.0.11",
"type": "module",

@@ -27,4 +27,6 @@ "description": "Alternative JavaScript/TypeScript runtime for ANTLR4",

"devDependencies": {
"@mike-lischke/antlr-tgen": "1.0.7",
"@types/jest": "29.5.11",
"@types/node": "20.10.4",
"@types/unicode-properties": "1.3.2",
"@typescript-eslint/eslint-plugin": "6.14.0",

@@ -40,19 +42,19 @@ "@typescript-eslint/parser": "6.14.0",

"ts-node": "10.9.2",
"typescript": "5.3.3"
"typescript": "5.3.3",
"unicode-properties": "1.4.1"
},
"scripts": {
"prepublishOnly": "npm run build-minified && npm run test",
"prepublishOnly": "npm run build && npm run test",
"tsc": "tsc --watch",
"build": "npm run generate-test-parser && tsc && npm run build-cjs && npm run build-mjs",
"build-minified": "npm run generate-test-parser && tsc && npm run build-cjs-minified && npm run build-mjs-minified",
"build-bundle": "esbuild ./src/index.js --main-fields=module,main --bundle --sourcemap",
"build": "npm run generate-test-parsers && tsc && npm run build-cjs && npm run build-mjs",
"build-bundle": "esbuild ./src/index.js --main-fields=module,main --bundle --target=esnext --keep-names",
"build-mjs": "npm run build-bundle -- --outfile=dist/index.mjs --format=esm",
"build-mjs-minified": "npm run build-mjs -- --minify",
"build-cjs": "npm run build-bundle -- --outfile=dist/index.cjs --format=cjs",
"build-cjs-minified": "npm run build-cjs -- --minify",
"full-test": "npm run test && npm run run-benchmarks",
"generate-xpath-lexer": "node cli/index.js -Dlanguage=TypeScript -o src/tree/xpath/generated -no-visitor -no-listener -Xexact-output-dir src/tree/xpath/XPathLexer.g4",
"full-test": "npm run test && npm run run-benchmarks && npm run time-lexer-speed",
"test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --no-coverage",
"generate-test-parser": "node cli/index.js -Dlanguage=TypeScript -o tests/benchmarks/generated -visitor -listener -Xexact-output-dir tests/benchmarks/MySQLLexer.g4 tests/benchmarks/MySQLParser.g4",
"generate-xpath-lexer": "node cli/index.js -Dlanguage=TypeScript -o src/tree/xpath/generated -no-visitor -no-listener -Xexact-output-dir src/tree/xpath/XPathLexer.g4",
"generate-test-parsers": "./build/generate-test-parsers.sh",
"generate-runtime-tests": "antlr-tgen --config tests/fixtures/config.json",
"run-benchmarks": "node --no-warnings --experimental-vm-modules --loader ts-node/esm tests/benchmarks/run-benchmarks.ts",
"time-lexer-speed": "node --no-warnings --experimental-vm-modules --loader ts-node/esm tests/api/perf/TimeLexerSpeed.ts",
"profile benchmarks": "node --no-warnings --experimental-vm-modules --prof --loader ts-node/esm tests/benchmarks/run-benchmarks.ts",

@@ -65,3 +67,7 @@ "process profile tick file": " node --prof-process isolate-0x130008000-75033-v8.log > processed.txt"

"import": "./dist/index.mjs"
}
},
"browserslist": [
"defaults and fully supports es6-module",
"maintained node versions"
]
}

@@ -110,6 +110,41 @@ [![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/mike-lischke/antlr4ng/nodejs.yml?style=for-the-badge&logo=github)](https://github.com/mike-lischke/antlr4ng/actions/workflows/nodejs.yml)

## Benchmarks
## Tests and Benchmarks
This runtime is monitored for performance regressions. The following tables show the results of the benchmarks previously run on the JS runtime and on last release of this one. Warm times were taken from 5 runs with the 2 slowest stripped off and averaged.
This runtime is monitored for performance regressions. The times below were taken on a Mac Studio M1 Max with 32GB RAM (Sonoma 14.2).
### Running the Tests
There are a number NPM scripts in the project that are related to testing. The first step is the generation of the test parsers:
```bash
npm run generate-test-parsers
```
followed by the generation of the runtime tests:
```bash
npm run generate-runtime-tests
```
and the build of the package:
```bash
npm run build-minified
```
After that you can either execute different suites separately or as a whole.
|Test|Script|
|---|---|
|Unit tests|`npm run test`|
|Lexer speed test|`npm run time-lexer-speed`|
|Real world example|`npm run run-benchmarks`|
| All together|`npm run full-test`|
The unit tests consist of tests for individual classes in the runtime (API tests) and the runtime test suite ported from Java. They execute in about 10s.
### Real World Example
The following tables show the results of the benchmarks previously run on the JS runtime and on last release of this one. Warm times were taken from 5 runs with the 2 slowest stripped off and averaged.
Pure JavaScript release (with type definitions):

@@ -128,13 +163,7 @@

| ---- | -------- | ------- |
| Query Collection| 6020 ms | 314 ms |
| Example File | 1059 ms | 181 ms |
| Large Inserts | 13722 ms | 13657 ms |
| Total | 20933 ms | 13658 ms |
| Query Collection| 6089 ms | 331 ms |
| Example File | 1064 ms | 191 ms |
| Large Inserts | 14742 ms | 14326 ms |
| Total | 21954 ms | 14869 ms |
The numbers are interesting. While the cold run for the query collection is faster with pure TS, the overall numbers in warm state are worse. So it's not a pure JS vs. TS situation, but something else must have additional influence and this will be investigated. After all the TypeScript code is ultimately transpiled to JS, so it's probably a matter of how effective the TS code is translated to JS.
Overall the numbers in the pure TS runtime are pretty good, especially when comparing them with [antlr4ts](https://github.com/mike-lischke/antlr4wasm/tree/master/benchmarks/mysql).
### About the Benchmarks
The benchmarks consist of a set of query files, which are parsed by a MySQL parser. The MySQL grammar is one of the largest and most complex grammars you can find for ANTLR4, which, I think, makes it a perfect test case for parser tests.

@@ -148,4 +177,51 @@

### Lexer Speed Test
Since the Java runtime tests have been ported to TypeScript there's another set of benchmarks, the lexer speed test. This set of tests was created when Unicode support landed in ANTLR4 and measures the speed of lexing different Unicode lexems in a lexer generated from the Java grammar.
The original Java execution times have been taken on OS X with a 4 GHz Intel Core i7 (Java VM args: `-Xms2G -Xmx8g`):
```bash
load_new_utf8 average time 232µs size 131232b over 3500 loads of 29038 symbols from Parser.java
load_new_utf8 average time 69µs size 32928b over 3500 loads of 7625 symbols from RuleContext.java
load_new_utf8 average time 210µs size 65696b over 3500 loads of 13379 symbols from udhr_hin.txt
lex_new_java_utf8 average time 439µs over 2000 runs of 29038 symbols
lex_new_java_utf8 average time 969µs over 2000 runs of 29038 symbols DFA cleared
lex_new_grapheme_utf8 average time 4034µs over 400 runs of 6614 symbols from udhr_kor.txt
lex_new_grapheme_utf8 average time 4173µs over 400 runs of 6614 symbols from udhr_kor.txt DFA cleared
lex_new_grapheme_utf8 average time 7680µs over 400 runs of 13379 symbols from udhr_hin.txt
lex_new_grapheme_utf8 average time 7946µs over 400 runs of 13379 symbols from udhr_hin.txt DFA cleared
lex_new_grapheme_utf8 average time 70µs over 400 runs of 85 symbols from emoji.txt
lex_new_grapheme_utf8 average time 82µs over 400 runs of 85 symbols from emoji.txt DFA cleared
```
The execute times on last release of this runtime have been measured as:
```bash
loadNewUTF8 average time 358µs size 29191b over 3500 loads of 29191 symbols from Parser.java
loadNewUTF8 average time 74µs size 7552b over 3500 loads of 7552 symbols from RuleContext.java
loadNewUTF8 average time 122µs size 31784b over 3500 loads of 13379 symbols from udhr_hin.txt
lexNewJavaUTF8 average time 610µs over 2000 runs of 29191 symbols
lexNewJavaUTF8 average time 4817µs over 2000 runs of 29191 symbols DFA cleared
lexNewGraphemeUTF8 average time 12973µs over 400 runs of 6614 symbols from udhr_kor.txt
lexNewGraphemeUTF8 average time 13151µs over 400 runs of 6614 symbols from udhr_kor.txt DFA cleared
lexNewGraphemeUTF8 average time 18051µs over 400 runs of 13379 symbols from udhr_hin.txt
lexNewGraphemeUTF8 average time 18228µs over 400 runs of 13379 symbols from udhr_hin.txt DFA cleared
lexNewGraphemeUTF8 average time 329µs over 400 runs of 85 symbols from emoji.txt
lexNewGraphemeUTF8 average time 387µs over 400 runs of 85 symbols from emoji.txt DFA cleared
```
## Release Notes
### 2.0.11
- Fixed bug #30 ReferenceError: Super constructor may only be called once
- The entire runtime test library from the Java runtime has now been ported to TypeScript and is used from now on to check the correctness of this runtime.
- The bit set class used bigint to store the values, which is a problem with bundlers like webpack that have no support for bigint. For this reason that type has been replaced (PR #40 feat: replace bigint and BigUint64Array).
- The bundle is no longer minified and hence larger than before. Bundling a minfied bundle with other bundlers (like terser) in dependent projects might cause trouble. Additionally, minifying a bundle has no benefit in execution time, it's just a size difference (related bugs: #31, #34, #38).
### 2.0.10

@@ -152,0 +228,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc