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

WASM? #222

Open
ghost opened this issue Nov 28, 2021 · 12 comments
Open

WASM? #222

ghost opened this issue Nov 28, 2021 · 12 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ghost
Copy link

ghost commented Nov 28, 2021

Parsers and WebAssembly go hand in hand. Kinda surprised this hasn't been suggested already!

@Mingun
Copy link
Member

Mingun commented Nov 28, 2021

If you want to create a WASM module for your parser definitions, probably it is better to write parser on Rust using rust-peg (this project obviously was inspired by pegjs, if you look at the project internals and it's grammar language is still very close to the language used by pegjs/peggy). Rust can be compiled to wasm module directly.

@hildjj
Copy link
Contributor

hildjj commented Nov 28, 2021

Mingun's answer is good for today, but there's no reason why can't generate WASM directly from peggy one day. It could be done as a plugin to keep the runtime dependencies low for the core project (like https://github.com/metadevpro/ts-pegjs)

@ghost
Copy link
Author

ghost commented Nov 28, 2021

Like, are you suggesting making a plugin that generates a Rust parser then compiles to WASM?

@ghost
Copy link
Author

ghost commented Nov 28, 2021

Also what if we figured out a way to use the ANSI C plugin? Would there be a performance benefit?

@hildjj
Copy link
Contributor

hildjj commented Nov 28, 2021

I was thinking the plugin could generate WASM directly, then either call back into JS for the actions, or use something like AssemblyScript to compile the actions themselves.

@hildjj
Copy link
Contributor

hildjj commented Nov 28, 2021

For generation, something like binaryen.js probably gets us there with only a lot of work involved.

@ghost
Copy link
Author

ghost commented Dec 15, 2021

I'm trying to run the Textmate scope selector parser in microsoft/vscode-textmate#52 (comment) but the performance is very bad on lower-end CPUs because of the parser's recursion. 😔 Looks like I will have to start cramming Rust and researching rust-peg over in the weekend.

@hildjj
Copy link
Contributor

hildjj commented Dec 16, 2021

Can you check to see if this makes things any better?

segment
	= _ segment:([a-zA-Z0-9+_][a-zA-Z0-9-+_]*) _ {
		return new matchers.SegmentMatcher(segment);
	}

(just removes the + from the first [] grouping, which shouldn't change your semantics)

@ghost
Copy link
Author

ghost commented Dec 16, 2021

Wait, trying it again now..

@ghost
Copy link
Author

ghost commented Dec 16, 2021

Broke the parser when I tried to feed it a wildcard

@ghost
Copy link
Author

ghost commented Dec 20, 2021

I cached the generated matcher functions AND their output and the performance improved :)

@hildjj hildjj added enhancement New feature or request help wanted Extra attention is needed labels May 21, 2022
@hildjj
Copy link
Contributor

hildjj commented May 21, 2022

Leaving this open as the feature request for WASM support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants