parinfer

tianshu 2018-03-15T00:03:01.000297Z

@eraserhd if it can process 3k loc in less than 10ms, I will port it to emacs. i'm not sure about the tradeoff of the dynamic module in emacs, but i hope it is fast.

justinbarclay 2018-03-15T00:46:24.000198Z

I'm new to both Elisp and Rust... but if there is anything I can do to help with this port, I would love to try.

eraserhd 2018-03-15T00:58:56.000038Z

I'm going to port the parinfer performance tests in the near future. Not feeling well enough this evening, tho. We'll see. I think there's probably plenty of room for optimization.

shaunlebron 2018-03-15T04:46:36.000172Z

@eraserhd catching up on these, congrats and thanks for the port 🎉

eraserhd 2018-03-15T14:24:25.000663Z

benchmarks:

test bench_indent_long_map_with_strings                ... bench:     253,694 ns/iter (+/- 28,165)
test bench_indent_really_long_file                     ... bench:   4,843,581 ns/iter (+/- 487,407)
test bench_indent_really_long_file_with_unclosed_paren ... bench:   4,726,135 ns/iter (+/- 490,493)
test bench_indent_really_long_file_with_unclosed_quote ... bench:   4,717,151 ns/iter (+/- 343,240)
test bench_paren_long_map_with_strings                 ... bench:     219,855 ns/iter (+/- 25,256)
test bench_paren_really_long_file                      ... bench:   4,395,875 ns/iter (+/- 366,891)
test bench_paren_really_long_file_with_unclosed_paren  ... bench:   4,288,902 ns/iter (+/- 452,732)
test bench_quote_really_long_file_with_unclosed_quote  ... bench:   4,368,507 ns/iter (+/- 638,843)
test bench_smart_long_map_with_strings                 ... bench:     255,331 ns/iter (+/- 30,632)
test bench_smart_really_long_file                      ... bench:   4,803,301 ns/iter (+/- 448,064)
test bench_smart_really_long_file_with_unclosed_paren  ... bench:   4,802,458 ns/iter (+/- 668,362)
test bench_smart_really_long_file_with_unclosed_quote  ... bench:   4,713,028 ns/iter (+/- 1,180,312)

eraserhd 2018-03-15T14:27:59.000208Z

@doglooksgood really_long_file is 2,864 lines. These benchmarks don't test marshalling/and unmarshalling with JSON or the Rust FFI, though. Just the rust package functions.

tianshu 2018-03-15T14:41:08.000151Z

@eraserhd average 4 ms? great performance, rust is really fast

eraserhd 2018-03-15T14:41:57.000177Z

Uhuh. I'm pretty happy with it. I even got sloppy with the performance in a bunch of places to make the port parallel the JavaScript more.

eraserhd 2018-03-15T14:45:26.000139Z

On my machine, seems consistently 1/4th the runtime of the JavaScript.

eraserhd 2018-03-15T14:46:03.000835Z

Actually, there's a lot more variance in the JavaScript. I think there's some GC going on in the longer ones.

tianshu 2018-03-15T14:57:58.000588Z

have you done the job to use it in vim?

eraserhd 2018-03-15T14:58:29.000209Z

Yeah. In the repo, the vim script is in plugin/

eraserhd 2018-03-15T14:58:39.000465Z

Essentially there's one function, "run_parinfer" which takes a UTF8 JSON blob and returns one.

tianshu 2018-03-15T15:01:02.000806Z

so, you haven't make it run after each buffer change?

eraserhd 2018-03-15T15:02:38.000845Z

Oh, yes, it does that.

eraserhd 2018-03-15T15:53:31.000245Z

OK, out of my meeting. What I was saying was that the "libcall" entry point is run_parinfer which taskes a JSON blob and returns one. There's a big of glue script that makes the JSON, sends it, unpacks the result, and updates the buffer. So, run_parinfer is what you would call from emacs.

eraserhd 2018-03-15T15:54:05.000978Z

(and it registers to handle Vim's TextChanged event)

tianshu 2018-03-15T16:13:25.000601Z

I see, so basically I should start with the cparinfer.

tianshu 2018-03-15T16:13:53.000866Z

It's pretty simple to port it to emacs, parinfer-rust is great.

🎉 2
tianshu 2018-03-15T16:16:13.000650Z

I will do it at next week.

shaunlebron 2018-03-15T16:22:32.000825Z

is it possible to compile this to wasm?

shaunlebron 2018-03-15T16:22:56.000285Z

so we don’t have to write js

snoe 2018-03-15T17:03:01.000611Z

the rust irc is super helpful if you ran into difficulties trying to

dominicm 2018-03-15T17:04:03.000745Z

How do those benchmarks compare to other implementations.

eraserhd 2018-03-15T20:22:56.000223Z

I would definitely love to try compiling rust to webassembly. No clue how it will perform. I've played with webassembly for about an hour total, and know it would need a JavaScript wrapper to work.

snoe 2018-03-15T21:25:50.000126Z

From what I’ve heard, the wasm ffi is really slow right now. I wonder if you have “pointers” into the js objects like webgl bytearrays or do you need to copy strings?

shaunlebron 2018-03-15T23:00:25.000443Z

kevin walked me through how he wired wasm/js stuff for subform-layout last week: https://github.com/lynaghk/subform-layout

shaunlebron 2018-03-15T23:02:14.000366Z

it’s an alternate layout engine for CSS, and it seems to be very fast—so i’m not sure what exactly you mean by wasm ffi being slow? @snoe

shaunlebron 2018-03-15T23:04:31.000350Z

in this demo, subform_init_layout loads the wasm code from a base64 string (internally), then passes the function wrapper to a callback when done: https://codepen.io/lynaghk/pen/Jpevwj

justinlee 2018-03-15T23:09:12.000007Z

slightly off topic, but subform is an amazing piece of technology. i’ve always wondered if layout wouldn’t be easier without css.

đź‘Ť 2