HNHacker News
TopNewBestAskShowJobs

jordwalke

1,558 karma · joined June 12, 2013

Building things at Facebook: React. ReactNative. ReasonML.

https://twitter.com/jordwalke

submissionscomments
jordwalke··on Reason: A new interface to OCaml
Facebook has many projects that are already written in OCaml, and Reason provides a path forward for seamlessly, and incrementally moving projects over to the new syntax/style.

Feel free to take a look at some Reason in the wild, used inside of the Infer project at Facebook:

https://github.com/facebook/infer/tree/master/infer/src/IR

Apart from that, although syntax is the "user interface" to a language, and user interfaces are very important, there really is so much to a language beyond the syntax. I see Reason's syntax as a way to make the really good parts of OCaml exposed to a wider audience, while making existing OCaml developers more productive in their editors.

Some things you might appreciate about OCaml's core language (which Reason provides a new interface to):

- World class pattern matching.

- Excellent type inference.

- Bare metal compilation without a VM, but alternatively the ability to compile into JS.

- Great predictable performance, even without a ton of performance optimizations (because the runtime is so simple), but take a look at 4.03 which includes a new F-lambda optimization pass. Even without F-lambda the perf is competitive with other systems languages, and F-lambda buys you another good 10-30% reduction in CPU or so.

- Multicore support is progressing. Here's a PR from today to add multicore support to the native backend (https://github.com/ocamllabs/ocaml-multicore/pull/47)

jordwalke··on Reason: A new interface to OCaml
Please take a look at the FAQ which describes the best way to move forward with evolving the syntax. It helps to know your personal technical background and where you're coming from, as well. I do like your idea, but you can currently use parens - it's just that they aren't required by the parser when the argument is clearly one item (like an integer constant etc). Then at that point, it's just a matter of configuring the source formatter to always include them.
jordwalke··on Reason: A new interface to OCaml
Cheng Lou fixed the firefox issue. Refresh and it should be fixed. Thanks again for reporting.
jordwalke··on Reason: A new interface to OCaml
We just discovered the same by disabling the media query which handles the shadow. Thank you very much for investigating.
jordwalke··on Reason: A new interface to OCaml
See the FAQ, as this is a fairly anticipated question. There's some benefits to having some token to separate let bindings and statements, so that the grammar is unambiguous, and it doesn't matter too much which token is used (monkey emoji anyone?) However, I think it may be possible to eliminate delimiters altogether eventually. Because we have the `refmt` program which can convert and beautify between two arbitrary versions of the syntax, we'll be able to automatically upgrade your code if we do find a way to eliminate delimiters unambiguously. Stay tuned.
jordwalke··on Reason: A new interface to OCaml
Thanks for the thoughts. I would definitely not call Reason a new language, but rather a new interface to an existing language that is already great. Not all languages make it easy to provide such an interface, but OCaml did, and the timing made sense.
jordwalke··on Reason: A new interface to OCaml
Thanks, we're looking into how to fix the perf in FF. Meanwhile, it works on my tiny mobile cell phone.
jordwalke··on Reason: A new interface to OCaml
For now, that's somewhat accurate. If you check out the JS comparison page, you might say it looks like JS with OCaml's influence.

The point of the syntax toolchain is actually not to get it right on the first try but to make something viable that is easier to learn/read, avoid bike-shedding, and put all the right tooling in place so that we can very seamlessly upgrade after taking in feedback. It's pretty liberating to know you have that ability to move forward rapidly and automate all of the upgrades.

jordwalke··on Reason: A new interface to OCaml
Thanks there's some strange font rendering issues. Will fix! edit: now fixed.
jordwalke··on Reason: A new interface to OCaml
Sounds like FF can't handle gifs, but Chrome/Safari do a good job. I've disabled the gif on the main page just to be friendly to FF while I figure out a better approach. Thanks for the report.
jordwalke··on Reason: A new interface to OCaml
Chrome and Safari both worked for me. Common reports about Firefox, so I disabled the gif. Can you let me know if it works now?
jordwalke··on Reason: A new interface to OCaml
Pretty sure it was the gif. I've disabled it. Could you try again?
jordwalke··on OCaml 4.03.0 released (including flambda)
Note that multicore includes two separate "features": the algebraic effects abstractions, and the multi-core runtime (domain heaps). From what I understand, OCaml's multi-core effort will include both of these as well as some improvements to garbage collection.
jordwalke··on Developing Our First iOS App with React Native
It's not incredibly advanced: It mostly just consists of measuring where exactly the current text box is in the scroll view, how high the text box is, and then having the scroll view scroll to that location, followed by fading in a docked text input right on top of the underlying one. It's pretty slick, but I'd encourage the community to recreate it in a reusable component and open source it.
jordwalke··on Developing Our First iOS App with React Native
I've implemented one solution to this in FB's Groups App. Try that experience out and let me know what you think. Also, Nick Lockwood should comment here.
jordwalke··on Opam-ios: an OCaml compiler for iOS via opam, with example server code
Here are some things that make ML (and OCaml in particular) a desirable language for mobile development.

1. Sound, static typing prevents entire classes of errors. This becomes even more important when you are shipping an irrevocable binary to users which you cannot update after the fact.

2. That same static typing can prove safe the removal of data boxing, and run-time lookup in order to increase performance.

3. OCaml (`ocamlopt`) does not run your program in a "Virtual Machine" like Java - instead it compiles your code more directly into machine code like C++. Many (but not all) of the other functional languages compilers produce a byte code, and then rely on a JITed Virtual Machine to (hopefully) optimize your code at runtime. `ocamlopt` compiles your program into assembly and you can inspect that assembly ahead of time in order to understand how it will perform. There's always tradeoffs with this approach, but the benefit is that you do not need to wait for (or hope for) a JIT to optimize your code (or re-optimize your code when usage patterns change).

4. OCaml is strict (as opposed to lazy), fairly close to the metal, and maps to lower level instructions in a fairly straightforward way - you would not be very surprised if you were to inspect the assembly. OCaml also has two ways to create bindings to C code. One way is easy and automated, the other way has better performance.

5. OCaml has a reputation for being able to allocate tons of memory at an impressive rate. To the extent that is true (and I've not yet observed anything to the contrary) I would imagine that would make it well suited to building UIs that are rapidly re-rendered.

6. OCaml has an Objects type system extension which makes it easier to create bindings to platform APIs (which tend to follow an OO design).

7. OCaml has two compiler modes: `ocamlc` and `ocamlopt`. Both support separate compilation, which is indispensable when building UI applications, where tweaking/reloading is very common. `ocamlc` would be ideal for that rapid development phase because, although it produces slower programs, it compiles them significantly faster. `ocamlopt` is ideal for shipping because it produces faster executables.

8. OCaml does not require that you write only pure programs. This makes it much easier to integrate with existing platform/mobile code which is also typically not pure.

jordwalke··on When did we stop caring about memory management?
The article divides programming languages into two groups: Those that require you to manage memory manually and those that rely on language level managed memory. However, the examples of the managed memory languages also rely on language level Virtual Machines and/or JITs (which are critical to achieving excellent performance in those respective languages). Then, the article points out that the people using these "garbage collected languages" (which are also JITed (in a VM likely)) tend to have problems debugging performance issues. If he's right, then the examples aren't making the case very convincingly because the realm of languages with garbage collection isn't divided granularly enough in his analysis. The result is attributing the problem to a common language feature that they all share, without acknowledging that they also all share other very important features.

I'd never claim that understanding memory usage/allocation/freeing isn't important. It's important to understand how memory is used whether that be understanding how your collector handles generations of memory in a GC'd language, or whether it be understanding how your programming patterns cause a waterfall of destructor chains in a manually managed language. Often, understanding these things is difficult.

My claim was that, in my experience, the biggest difficulties in debugging performance were in understanding JIT heuristics in language level Virtual Machines. This is because (especially in dynamic languages) the heuristics aren't documented anywhere, they're subject to change, and are likely not consistent between particular runtimes you're hosted within. (Those optimizations you made just for V8, could even hurt perf if you run your library in JSC).

There's also the issue with language level virtual machines in that they usually impose some system wide tax on many operations (a layer of indirection), so I could see the people mentioned in the article having a hard time squeezing out that last portion of performance due to that indirection - again, that might be the fault of there being a language level Virtual Machine - and not necessarily as much related to memory (it depends on your application, and amount you allocate, of course).

In my experience, optimizing collection behavior has been relatively straightforward in comparison and the techniques you learn for one collector seem to translate to others. Perhaps my experience is biased towards JIT/VM/GC in dynamic languages where the JITs are so much more complex in comparison.

I have seen core hot paths in critical client side JS libraries be slowed down 9x because of obscure JIT deopts caused by properties names beginning with a dollar sign. I'm not just talking about a 9x slowdown of field lookups - our entire end to end benchmarks tanked (since fixed). Perhaps the VM architects decided that something with a leading dollar sign would not likely benefit from being made into a hidden JIT class? I've never had anything so obscure happen with any kind of garbage collection, whether that be reference counted ARC, or a tracing collector. Edit: spelling

jordwalke··on When did we stop caring about memory management?
This article conflates two separate issues: Automatic memory management, and Virtual Machine runtimes. People often make the mistake of thinking that some sort of garbage collection strategy (such as reference counting[1] collection (ARC) or tracing collectors) implies that you must be running in a VM (which typically employ some kind of JIT to achieve reasonable performance). This is not true - see Haskell, OCaml, SML, and Swift (for reference counting collection).

In my experience, many of the issues with debugging performance issues are not related to memory management, but understanding JIT heuristics which are moving targets (especially in the dynamically typed languages).

I think we need to collectively separate the idea of some kind of automated (or semi-automated) collection strategy, from a language level JITed Virtual Machine. You may have one without the other.

[1]https://www.cs.virginia.edu/~cs415/reading/bacon-garbage.pdf

jordwalke··on OCamlScript – a JavaScript back end for OCaml
Question for hongboz and Drup about F-lambda:

OCamlScript does some cross-module optimization it seems. That's really cool, and js_of_ocaml does several optimizations as well, but for both approaches, it seems we'll not be able to take advantage of all really great f-lambda optimizations to come because they happen at a compiler stage after OCamlScript and js_of_ocaml have already intercepted their intermediate representations. Do you (or Drup) have thoughts on that?

jordwalke··on OCamlScript – a JavaScript back end for OCaml
It would be great to see a list of known/anticipated compatibility issues. For example, I notice that when compiling `String.set` with OCamlScript, the generated JS ends up trying to set/mutate a character in the JS string, which has no effect because JS strings are immutable. (I'll file a github issue). I imagine there will be several small issues like this and it would be good to get a sense for how much work it would be to solve that long tail of compatibility work. In the process, I think the community can help determine if this approach could ever practically match the near-perfect level of compatibility that js_of_ocaml has achieved via byte code compilation - and whether or not it matters. To me, compatibility is very important, but so is debugability. It might be clear that it's okay to compromise the readability of OcamlScript in order to achieve more compatibility without compromising debugability (for example, using a `new MLString("xyz")` wrapper that uses a JS `String` by default for performance, but then swaps it out upon any mutation. (Or perhaps you can limit it to programs that have disabled string mutations in later versions of OCaml).

The good news is that if you can achieve perfect compatibility with this approach, then I believe that runtime performance becomes less of a concern and OCamlScript's job gets a lot easier. This is because, if you've achieved perfect compatibility, you can easily compile your project with another toolchain such as js_of_ocaml, that has equal compatibility, but (in this hypothetical scenario) had chosen to focus more on performance instead of debugability - without changing anything in your program.

This would free you up to not have to worry about applying any optimizations in this readable/debuggable mode - you get to focus entirely on whatever makes the development flow faster/easier. (You'd probably still want tail call optimization because order of memory usage could be considered a key part of compatibility).

Similarly, I wonder if the existence of a fully compatible, (hypothetically) slow runtime performance, but perfectly debugable compiler backend, would then free up js_of_ocaml from some of the constraints/work that is required to make their code output reasonably simple/debuggable. Does the existence of a fully compatible OCamlScript mean that js_of_ocaml's job gets easier?

I'm excited to discuss how the two projects could potentially become an asset to each other.

edit: I started a discussion on Github here: https://github.com/bloomberg/ocamlscript/issues/12

jordwalke··on OCamlScript – a JavaScript back end for OCaml
Before that, I'd ask if the implementation of OCaml's map is at all similar to the implementation of Immutable.js's Map. Different internal data structures/algorithms are probably the most likely explanation for any difference. Still, it's nice to see a benchmark that shows how OCaml compiled to JS is competitive in performance, even when compared to a very popular library that is known for performing well.
jordwalke··on OCamlScript – a JavaScript back end for OCaml
Drup:

Also, if it wasn't abundantly clear (to you or others) - I believe js_of_ocaml to be perhaps the best systems language compile-to-js toolchain that I've ever discovered (and I've looked extensively for others) - so I hope you can fully appreciate just how valuable it continues to be, to me personally and many others.

I have a question about your comment: "It's probably pretty easy to improve js_of_ocaml on that though, given the current state."

Would this also require patching the compiler to preserve record field names and avoid name mangling in general?

And I have a question about your comment on reddit which implies that maintaining a backend would be difficult to sustain: Do you believe that a seamlessly debuggable JavaScript backend, could generate the necessary amount of attention required to sustain such a backend, given how much more widely accessible end-end OCaml development would become as a result of its existence?

jordwalke··on OCamlScript – a JavaScript back end for OCaml
Drup, By the way, I really have appreciated the absolute simplicity of js_of_ocaml - it's pretty great how you can just take any byte code file and run it in any JS engine with great performance - it's amazing really. I really love how js_of_ocaml does dead code elimination, and inlining among other features.

It seems like the primary difference is that the goals of js_of_ocaml gravitate more towards taking an app/library that had already been fully tested/debugged in OCaml and then running that thing in the browser with some nice debugging facilities that let you see the source code and kind of step through in the more rare event that something goes wrong.

I can't speak for this new approach here, but it seems to be more focused on using the JS target as the core development workflow for rapid iteration. I can see why that's appealing. Everyone knows how to use the browser debugger, and JS is one of most ubiquitous byte code formats ever. Running your OCaml app in the browser also gives you all kinds of really great timing and memory profiling tools that help you detect leaks (that even tells you something about the nature of your program when compiling OCaml to machine code).

Obviously, I wish there was a single toolchain that could actually do both though - a toolchain that you could use to get very JS-friendly code generation so the debugging/value printing/console inspection works just like it does in JS, but then would also let you do a js_of_ocaml style compilation based purely on an OCaml byte code object file (edit: or some kind of representation of the whole program) which would be free to remove and obscure record field names if it so chose.

(BTW: The difference in object representation (record field names are not obscured) seems to be the very thing that makes the values inspectable in the browser. Maybe there are some of OCamlScript's compiler patches that could be accepted in upstream ocaml so that the same can be achieved with js_of_ocaml?).

jordwalke··on OCamlScript – a JavaScript back end for OCaml
I made github issues to discuss the name collision as well as allowing the compiler patches to be applied via an OPAM switch.
jordwalke··on OCamlScript – a JavaScript back end for OCaml
Drup, Ah, yes - CommonML does indeed have built in support for js_of_ocaml.

And I think you have valid points. I'm curious though, since both js_of_ocaml have seamless interop with JS (seamless in terms of memory model), couldn't the two have seamless interop between each other by going through JS bindings?

I'm curious, do you think it's possible or practical to create an OCaml to JS compiler that has the strengths of both approaches?

jordwalke··on OCamlScript – a JavaScript back end for OCaml
Hi Drup,

I'd be curious to hear about the work that Alain is doing. Do you have a link?

jordwalke··on OCamlScript – a JavaScript back end for OCaml
Small correction: I did not improve js_of_ocaml besides giving feedback (which included feedback about the need to not mangle names).

Before Babel for JS came out, there were tons of different solutions to compiling ES6 features into ES5, and the decision about which toolchain to use would fatigue newcomers to the community. But it was the fact that the community was relatively accepting of new spinoffs that Babel was able to gain momentum, and increase its quality to the point where it is the de factor tool that everyone uses - and it's really good.

As a consumer of the compiler, I don't necessarily consider multiple options a bad thing as long as something of really high quality emerges. (Although I can see how for something like an Async library (that introduces incompatibilities between dependencies) that would be particularly frustrating to have too many options)

It looks like OCamlScript used some good ideas from js_of_ocaml. Maybe js_of_ocaml can end up sharing some of the good ideas from OCamlScript so that it can also have very readable/debugable code and ecosystem integration?

jordwalke··on OCamlScript – a JavaScript back end for OCaml
This looks like it could be very useful. I've really enjoyed using js_of_ocaml, which supported source maps very nicely, but the value printing was often obscured because types and record field names were erased. This looks like it has much deeper integration with the host JS environment and ecosystem. Great work and I look forward to seeing where this goes.
jordwalke··on Why ML/OCaml are good for writing compilers (1998)
Other tracing collectors have certainly caught up since 1998, but I'd keep my eye on two things that have also happened since 1998:

1. Work by Damien Doligez which made further improvements to OCaml's current tracing collector (in 4.03) which further reduced pause times.

2. The multicore OCaml tracing collector work that's going on right now at Cambridge. If I understand correctly, this work involved not only partitioning memory into multiple thread local heaps, and a shared heap, but it also improved the collector in general.

I haven't tested it but I'm curious if the combination of this work will again put it ahead of other alternatives.

jordwalke··on Componentizing the Web
Do you believe that you would never find yourself feeling "locked in" to the features/capabilities of Web Components?
← PreviousPage 4 of 7Next →