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 Runtime.js – JavaScript library OS
> it's available on pretty much every platform

And now so is OCaml, Elm, PureScript, C++, and anything else that compiles to JS.

> it's a natural fit for web application development, and so on.

Now that other languages are beginning to compile to JS, they are also becoming increasingly natural for web app development.

> there's already a huge supply of developers familiar with it and its ecosystem.

This is definitely true.

jordwalke··on Runtime.js – JavaScript library OS
It's not clear to me and I don't have any experience with unikernels, so please accept my grain of salt and I apologize if I misspeak.

If you're starting with MirageOS, then obviously makes sense to just run MirageOS a bare-metal hypervisor. But if you're starting with the assumption that you will be running in a JS VM, then you have two options: build a unikernel in JS, or compile one to JS. The later option (MirageOS compiled to JS) also happens to leave open the possibility of easily being ran on a bare metal hypervisor with the unikernel implementation itself also running on bare metal (without a language level virtual machine) - because OCaml executes without a language level virtual machine (it's more like C++ in that sense).

> The obvious benefit of a JS VM unikernel is that you get to write your application in JavaScript...

What are some reasons why that would be a good thing in the case of unikernels? (I'm genuinely asking) The type system and invariants that it enforces are one of the things that makes OCaml based unikernels such a compelling idea to me. JavaScript, although I obviously find it useful for many things, doesn't seem to have as much appeal in this case.

Relevant to security: See MirageOS's Bitcoin Pinata project: http://amirchaudhry.com/bitcoin-pinata/

Edit: Again, it's still cool to see this project, and it's a great way to get more people experimenting with the idea of unikernels.

jordwalke··on Runtime.js – JavaScript library OS
A cool example: http://roscidus.com/blog/blog/2015/04/28/cuekeeper-gitting-t...
jordwalke··on Runtime.js – JavaScript library OS
This looks really cool, I look forward to following the project.

I'm curious, if you wanted your unikernel to be running in a JS VM (I'm not sure what the primary motivation would be[deployment?]) why not take the approach of just compiling the type-safe MirageOS into JavaScript (possible because MirageOS/OCaml can also compile into JS). Unikernels are attractive because of, among other reasons, increased security. It's pretty well understood that a powerful type system (such as Mirage's use of OCaml) would be useful in reducing accidental security vulnerabilities as well. Come to think of it, I'd much rather trust mission critical server infrastructure to OCaml that compiled to JavaScript, over JavaScript. At the end of the day, you'd still be able to use it from within js via `require('OS')`, but its implementation would have had more bugs/vulnerabilities prevented by the type system.

jordwalke··on OCamlers' critiques of Haskell
I am an unashamed OCaml fan, but I think my previously stated analogy is suitable:

"FP communities: like debating which brand of natural spring water to give millions of thirsty people in the desert"

https://twitter.com/jordwalke/status/566719390272335872

Note that I do genuinely appreciate the discussion, while finding the overall scene humorous.

jordwalke··on Reviewing the Bitcoin Piñata
I'm interested as well, but I can't help but laugh at the fact that we're asking about ways to reduce the size of an 8MB production operating system/stack.
jordwalke··on A brief introduction to OCaml
For serious development, yes, but consider the people who are learning OCaml. One of the first programs is going to be some kind of side effecting hello world etc.
jordwalke··on A brief introduction to OCaml
Single semicolons simply evaluates several expressions and returns the last one, but if you use them in a module definition (like every file is by default), you'll be coerced into using double semis.

The advantage over your version (with the single semicolon) is that in your version, you cannot now create a standard exported module value binding after that single semicolon, because the parser interprets that next let binding as a continuation of the single semicolon expression, so your only hope is to use double semis to escape back to normal module body parser context.

Function bodies (or any other expression really) don't have that same issue, but I might suggest avoiding single semicolons even in that case so that you have fewer edge cases to memorize. Here is the simplest possible convention I can think of that requires the smallest amount of memorization:

- Forget about all semicolons, single or double (just think of ;; as a way to press enter in the top interactive REPL).

- Module bodies (like every file by default) are just exporting a series of bindings. If you want to evaluate an imperative command inside a module body, export its result to "_".

- Function bodies are expressions. If you want to evaluate an imperative command inside a function body (or any other expression), use `let in` like you would for any other temporary variable, but use the variable name "_" and simply don't use it.

jordwalke··on A brief introduction to OCaml
It's easy to get a quick comparison by searching stackoverflow so I won't reitterate those answers, but I would just mention a couple of my favorite things from OCaml that F# doesn't have that those answers tend to leave out:

- Polymorphic variants

- GADTs

- Named arguments (that are still curried if you can believe it!)

- Last time I checked OCaml had better record label scoping. F# doesn't allow two record types in scope that share a record label name. Does anyone know if F# has plans to implement what OCaml has (or have they already?) OCaml used to have the same problem but it was fixed and now dealing with OCaml records has been massively improved as a result.

jordwalke··on A brief introduction to OCaml
So in this case, you can just imagine you are using F# then you should be happy with OCaml. (Configure utop as I suggested for the full effect).

That should at least clear up a small distraction for you so that you can make your decision based on fundamental strengths/weaknesses instead of aesthetics made inconsequential by configuration.

jordwalke··on A brief introduction to OCaml
This is also great cheat sheet for someone still getting used to the OCaml syntax.

I usually advise people to pretend that double semicolons don't exist for anything but the interactive top level. In source files, you can forget about double semis entirely as long as you just remember to always assign the result of an imperative statement to the dummy "_" name.

    let _ = print_string "hi"
Then you can think of ;;<enter> as merely a fancy way of hitting the return key in the interactive REPL. There's also a way to use a different key mapping (control+enter) instead of ;; in utop, so there would be no reason to even acknowledge the existence of double semis. https://github.com/diml/utop/issues/131
jordwalke··on OCaml Resources (2006)
js_of_ocaml is very well supported as well - in my personal experience.
jordwalke··on Santa Monica council votes 7-0 to crack down on Airbnb
I understand what you're saying. I'm not understanding who in the current situation has any right to have grievance. In a situation where apartments/homes allow airBnB in their bylaws/HOAs, everyone - the landlords, the neighbors (whether or not they rent) and the short-term renters are all acting in accordance with their legal agreements that they voluntarily agreed to.

In a situation where HOAs/bylaws do not allow renting on airBnb, there already exist proper legal channels for enforcing contracts, and these extra regulations are not needed.

Your comment made it seem like these extra regulations somehow ease these complaints (which you are implying are legitimate). Is my understanding correct?

jordwalke··on Santa Monica council votes 7-0 to crack down on Airbnb
>> "people buy or rent residences in buildings expecting those buildings to be inhabited by long-term residents, then some part of the building gets converted to a hotel"

But isn't that what Home Owners' Associations and condo bylaws are for? If you don't want to risk this happening in your apartment, don't buy one that permits other residents to do this. Thank you Market.

jordwalke··on Building a lower-latency GC
>> I do think your logic holds for many combinations of users and infrequently-used applications.

Do you consider the Facebook app infrequently used? Or virtually every other app in the iOS app store that has a UIControl embedded inside of a scroll view such that highlighting of elements is intentionally delayed? There is certainly a few frames worth of work that can be done while no interruptable animations are occurring and while no interaction is occurring. If you don't believe me, then I suggest you do what I often do: use a very high speed camera and examine your casual usage of an app. You'll find that you are much slower than you think you are.

jordwalke··on Building a lower-latency GC
>> This approach can still cause perceptible latency if the user tries to input something while the GC you were trying to hide is ongoing.

With all due respect, I think you're missing the point on this one. For non-games, there are times when blocking for n frames will be perceptible and times when it will not be and we know exactly when these are. Garbage collection (such as ARC) has nothing to do with that particular fact. It doesn't matter what you are doing during those times - you could be performing longer running computation, or garbage collection tasks (such as ARC deallocing large trees, or the JVM). The way this is handled in applications is by either offloading long running tasks to another thread of finding a way to distribute the time across several event loops (whether intentional or not). I'm proposing that the same techniques that we apply to other parts of our apps be applied to garbage collectors.

Also, that threshold for a continuous animation, is absolutely less than the threshold for perceptible instantaneous latency and that is determined by biology, not me. That means you have more time to work with when there is no animation ongoing but one could begin as the result of a tap, (or typing). Now, the OS/platform does consume a large part of this threshold - but that's a different story.

That's a good point about games never having an entire resting frame. But that brings me back to the first desirable GC feature - to provide a way for a GC to use the remaining frame time of thousands of frames, so that it can perform its work incrementally in the remaining time of each individual frame, without ever missing a display link deadline. I think both are important (sub frame yielding to incremental tasks like collections, and yielding entire frames (or two) to longer blocking tasks for applications that can withstand it). Games might not be able to take advantage of the later, but the majority of non-game apps that you have installed on your phone would certainly.

Some would argue that "for application types X there is no available frame time". I would say that is almost always false. Otherwise application type X would drop frames on any machine that was slightly less performant.

jordwalke··on Building a lower-latency GC
A few frames on top of the platform/OS/hardware latency may begin to cross into the threshold of perceptions for initiation of continuous movement. If your hardware already has 30ms of latency, then a few additional frames makes approximately 70ms. What you actually see with your eyes when your program consumes 30ms at the start of a scroll may be much larger.

However, you already have a few pixels (not time) of intentionally introduced slop in a scroll view. I'd like the ability to play with all of these constraints (including slop pixel amount), remaining frame time, acceptable latency for initiation of gestures, in order to reach what I consider to be a great user experience.

jordwalke··on Building a lower-latency GC
Another anecdote that has less to do with garbage collectors, but still shows the importance frame alignment:

I had been developing a UI interaction for a mobile app, and had been experiencing the strangest stutters while dragging. For the longest time, I blamed the garbage collector (which I realize is the lazy way out - no one will argue with you). However, I eventually realized that the exact same code that executed while dragging could be played on a screen-refresh-driven event and would be as smooth as butter. What was even stranger, is that my two year old iPhone 5 would execute this dragging interaction much more smoothly than my brand new iPhone 6+. Something was going on here clearly.

So I took the garbage collector out of the equation, and just measured the raw hardware events for screen refreshes and touch events and I found that touches may be coming in at a steady 60fps (just like the screen), but they were aligned in the middle of the frame. This was only happening on my higher end device, not on the lower end device which explains why my iPhone 5 felt better than my 6+. This is really bad because if your handler takes a mere 9ms, it will end up boarding the next train, along with the next* touch handler. So zero passengers hop on the first one, and two passengers hop on the next one. What we really wanted was one passenger per train in order to create smooth interactions/animations. What looked like a performance issue, is actually a simple alignment issue! What's worse, is that if you had a naive "fps counter", that must measured how many event handlers completed per second on average, it wouldn't drop below 60fps!

So not only is it important to be able to schedule work (GC or anything really during available frame time), it's important that we properly align this work with the screen refresh rate, both of which are things that can only be done above the language layer.

jordwalke··on Building a lower-latency GC
Sounds like amazing work is happening here.

For real time user applications such as games, newsfeeds, and mobile apps that have visual/audio feedback, I'm certain that the most important feature is the ability to have applications themselves control the process of collecting and the time constraints to operate within. It is possible to have a collector that is less efficient, but be entirely perceived to be more responsive as long as the wasteful or less efficient work is done at times when it does not matter - and this tradeoff would be gladly welcomed.

So much of UI application time is idle. Even during fluid animations, the majority of the frame time goes wasted. But then something like Objective-C's ARC frees large trees of memory, or perhaps Java's GC collects, and causes your frame time to exceed 16ms. For UI applications, there are periods of time (during animations) where you must hit 16ms deadlines, and the difference between 1ms and 15ms is nothing, but the difference between 16ms and 17ms is everything. UI application animations are like train schedules. If you miss one train by only a microsecond, you still have to wait the entire time until the next train arrives. You don't get points for almost making the train. Furthermore, only the application can know the train schedule. It isn't something the language runtime can possibly know, so to do this right, the language must anticipate this and accept input from the application frameworks.

Then there are other times when we are not performing an animation and we know that we could block a thread for as much as 50ms, without having any perceived delay experienced by the user. The latency constraints for starting a continuous interaction are larger than the constraints for continuing a continuous interaction. So in this case, our application still knows the train schedule, it's just a different train schedule that allows for more time to kill. If applications could tell the GC about this, it might decide that it's a good time to perform a major collection.

I've found that many of what people consider to be performance problems in UI applications aren't problems of efficiency, they're problems of scheduling.

jordwalke··on Why OCaml GADTs matter for performance
In my experience, a memory win takes place because you can use something lighter weight (ADTs) to model your data as opposed to something that consumes additional memory (objects or a record of bound functions) simply to get the type system to accept your code.

Furthermore, when using ADTs to store your data (and constructing modules that operate on them) I believe the resolution to the functions that operate on them are entirely done at compile time, not run time - whether or not that is being capitalized on is a different story, but I believe it has benefits now and will have even more later as the compiler authors continue to add more optimizations.

jordwalke··on From Bytecode to JavaScript: the Js_of_ocaml Compiler [pdf]
It would be nice to see updated benchmarks - I understand there have been many performance improvements in JS engines and js_of_ocaml since the original time of writing.
jordwalke··on From Bytecode to JavaScript: the Js_of_ocaml Compiler [pdf]
I'm glad I've had the chance to experiment with js_of_ocaml. I'd like to see continued effort to take advantage of all the potential optimizations, and tutorials/examples of using source maps (which are supported btw). So far, I am impressed with the potential!

JavaScript is clearly the world's most ubiquitous/targeted VM that performs well, and js_of_ocaml allows us to take advantage of that but with a sophisticated type system. Modern JS JITs can enable very high performance (especially JavaScriptCore in my experience), but the dark side is that it's easy to accidentally include a small piece of code that causes JIT deoptimizations.

When you start with a different source language (especially when it is statically typed) and use a controlled JS compilation toolchain, it allows the output to be generated in a way that is more likely to be stable in modern JITs. If there's an issue in the compilation, you fix it once and all apps built in the original source language are likely to avoid the issue. Furthermore, the compiled output could be tuned for particular JS engines, and servers (or app containers) can decide at the proper time, which version of the compilation the app should be executed with.

jordwalke··on “Implement text editor DOM updates manually instead of via React”
Ah, it's good to know we have an ally against a common foe and I respect that you're taking a different approach (I suspect you'd be interested in Mezzo). I'd really encourage you to try out React though. It's different than other FRP type systems because the granularity of "reactivity" is much larger (at the component level) which means the majority of your code executes on plain data structures such as arrays and objects. There's no need to continuously be lifting your data into some "reactive" data container. For example, if you have two numbers that are changing over time, if you want to add them, you use the + operator instead of creating some kind of "ReactivePlus" operator.

Also, in some types of apps, when you have many of these point to point bindings wired up, the bookkeeping of them can start to add up too, especially when everything ends up changing any time anything small changes. This hurts two cases predominantly: 1. Your initial rendering of the UI. You usually have to set up these point to point bindings. It would be faster to not have to when blocking the initial user experience (which is critical). 2. When small changes end up rerendering the entire page anyways. This is the worst time to be slow because you already have so much to do! If some small imperceivable delay becomes a medium imperceivable delay, it's not so bad. But when the entire scene changes all the time, a framework like React that anticipates this can cut right to the chase and do the rerendering without also having to do the bookkeeping along the way. Different apps will have different sweet spots in different paradigms. I will say that it's worked out well for us at Facebook/Instagram and many other serious production apps (not just simple examples). I'd encourage you to try it out and give us more feedback since you've done so much research in this area.

jordwalke··on “Implement text editor DOM updates manually instead of via React”
It's a great question. All of this (immutability) only makes sense to even attempt if you believe that immutability is easier to reason about than mutability. If we don't agree there, then I have nothing more to add really. But assuming we agree, then there is the question of performance.

In most applications, we have three tiers of time durations.

Tier One: During an interaction/animation you must update the screen every 16ms. Code may not run longer than 16ms (less in practice).

Tier Two: You are not interacting, but may begin interacting with something at some unknown time. Code may not block the UI thread for longer than about 50ms so that there is a guarantee of not introducing perceivable delays into the interface.

Tier Three: Long running tasks which should be executed in parallel with the UI thread/process.

If going from O(1) to O(log(n)) still allows you to meet your deadlines for whichever latency tier you are targeting in whichever supported device classes you want to support, then it's worth it in order to program with better abstractions. Blocking for 1ms is as good as blocking for 13ms in Tier 1. Blocking for 25.5 is as good as blocking for 40ms in Tier 2. (This is helped by a decent event loop/task scheduler etc).

Again, all of this assumes you genuinely value immutability as a programming paradigm over mutability. If you'd really rather mutate, then you should just be using mutations/observables. I would not rather. Sometimes, I still perform mutations for the most critical parts of a UI abstraction (such as a scroller animation etc) - but I am up front about it being a compromise of what I'd rather do.

jordwalke··on “Implement text editor DOM updates manually instead of via React”
Most of the people that don't believe that immutable, persistent data structures are effective tools to increase performance of reconciliation, only put one foot in (that's my personal experience). That kind of reservation often compels people to "just try immutability on a part of their tree". It doesn't work like that and you often should go all in before you begin seeing the benefits. It's a leap of faith, admittedly.

Almost every application (ever) is a list of lists of lists (and so on). Even text can be broken up into paragraphs/code-blocks etc which form the lists. If these structures form a tree, and that tree is somewhat well balanced, then small changes can be found in log(n) time by comparing reference identity without developer intervention (by either a mixin or Om-like system). log(n) ends up being extremely fast for n in the range of graphical nodes in most UI applications. For everything else, a windowing infrastructure can be used (usually baked into a very sophisticated <ListView> component - our ReactNative mobile applications use this approach (special <ListView> component that exploits immutability without developer intervention)).

jordwalke··on “Implement text editor DOM updates manually instead of via React”
(I'm on the ReactJS team at Facebook)

>> pathological case for something like React.

The is absolutely likely to be the case (for now). I admit I haven't looked into the technical issues very much because I've been spending 100% my time on ReactNative which seeks to resolve the deepest issues with the browser environment for React development - it's certainly a different kind of performance work.

For this kind of stuff, most people create a highly custom React base class that "cuts right to the chase" as far as updating small pieces that change in large lists. Immutable data structures are often the most helpful tool in accomplishing that. I'm sure they have totally legitimate reasons to go with this approach in the mean time, and most of all I want their project Atom to succeed because it's such a great idea. I hope we can help the Atom team soon to resolve these other issues though.

jordwalke··on Show HN: CommonJS Based OCaml Development
Looks like a great way to get sandboxing!
jordwalke··on Why OCaml, why now? (2014)
>> since otherwise, you can just bind the result of the functor to a structure once..

My understanding was that of lpw25's. I wanted to use applicative functors in the same way type classes (or OCaml's modular implicits) would make use of them, but even without type class's implicit resolution (explicitly specifying them). I agree there isn't too much difference from doing the same with generative functors, but the main difference is, as you said, I would need to find a place (some appropriately accessible location in the namespace) by which to access the result of these generative functor applications, and that's just an extra point of friction (if I understand correctly). It's not the end of the world as you said either way because we can do either.

Thanks for the help, jonsterling/lpw25.

jordwalke··on Why OCaml, why now? (2014)
I believe they are slightly beyond "syntax sugar". If I'm mistaken, I'd love to see the equivalent of what they desugar to. Some of the nuances that I believe OCaml's named arguments get right (and what greatly distinguishes them from passing a record) may require additional work in the type system beyond simple desugaring to something like records. Someone please correct me if I'm wrong.

- Partially applying arguments. You can apply one named argument, and get a function that expects the remaining named arguments. This is pretty great though confusing when you see it for the first time.

- Defaults for omitted arguments. If the caller doesn't specify an argument, you can define what should be used instead. This is kind of like the opposite of subtyping on record arguments. With structurally subtyped record arguments, you can pass a record that has more information than a certain minimum set of labeled fields. But with named optional arguments with defaults, you can pass less than a certain maximum number of labeled fields.

jordwalke··on Why OCaml, why now? (2014)
That's a nice approach for debugging! If the mapping is close enough, I don't mind reading the JS output. I'm curious about the general approach to compilation, though. It seems like a statically typed language could take advantage of the knowledge of types to generate an even more efficient version of the program that uses typed arrays and views (though, yes, it would require implementing a garbage collector unless relying on some kind of WeakMap in the JS engine). I've heard of garbage collected languages compiling to LLVM which would allow Emscripten to assist you, but I've also heard that LLVM has a really hard time with GC languages.
← PreviousPage 5 of 7Next →