Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Map<number, T> with sparse array in DFAState #468

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open

Replace Map<number, T> with sparse array in DFAState #468

wants to merge 31 commits into from

Conversation

BurtHarris
Copy link
Collaborator

@BurtHarris BurtHarris commented Apr 29, 2020

Interesting little optimization, possible because JavaScript Arrays are sparse. Up to 17% improvement in lexer speed. See #467.

@sharwell your feedback would be interesting. I (still) don't understand PredictionContext.EMPTY_FULL_STATE_KEY, and how it is treated in this code.

Are the other opportunities listed in #467 at all likely to make significant differences?

Burt Harris added 30 commits April 11, 2020 16:46
Use a relative path devDependency on antlr4ts-cli, that's cleaner.
Add steps to cleanup any npm global mess made before.
Added 'npm run reinstall' script for clean-up of truly ugly problems.
Note: reinstall involves a 'git purge -idx'.   It asks permission...
Disentangle imports / directory reorg
Makes antlr4ts more like the other ANTLR4 target directory structure
Build process now split out for packages, with each getting it's own package.json, and tsconfig.json.   Eliminate relative path imports anywhere outside the src/ directory.
checking in .d.ts files to track any api changes
Note: currently TypeScript v3.x is problematic in this context,
but 2.9 is OK
Implements suggestion in PR #454
Version 3.8.3 generates errors that don't seem right, so 3.7.5 it is.

Getting to V3.x gets us the new project build mode, which is a big win in terms of build time.   tsc will use tsconfig.tsbuildinfo files to manage an incremental compile which can really speed up many situations.  Switches used on tsc commands change for this mode.

One copy of the compiler, set in --watch mode, and watch the entire directory tree, performing compiles on change even if different parts of the tree uses different settings.

Making this work right requires a change in import statments.   None of them should ever reference the "src" directory, if needed use "dist" instead.
…sitory

To run antlr, we use the `lerna run antlr` command.   Any package that has an antlr script is run, lerna controls the ordering based on dependencies declared in the package.json files.

The typescript compiler has multi-package build-in (in V3+).  Combined
with a new incremetal compile feature, this is a big time savings.
Fixes: #459
Yet more fixes for tslint gripes
@NotNull, @nullable, @SuppressWarnings- typescript native alternatives
@OverRide - Use retained as comments for documentation
internal.ts becomes the single controlling point for module load order
fixes: #466
@@ -59,12 +59,17 @@ export class DFASerializer {
states.sort((o1, o2) => o1.stateNumber - o2.stateNumber);

for (const s of states) {
const edges: Map<number, DFAState> = s.getEdgeMap();
const edges: Array<DFAState> = s.getEdgeMap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 Why Array<DFAState> instead of DFAState[]? I'm sure I used to know the answer...

Copy link
Collaborator Author

@BurtHarris BurtHarris Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are the same thing. It just was easier to textually substitute without changing the trailing '>'.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to hear from you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S. most of these changes are from earlier PR #454.

@BurtHarris BurtHarris linked an issue Apr 30, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace Map<number,T> with (sparse) Array<T>
2 participants