Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the "types first" Flow architecture?

A blog post by the Flow team describes a "re-architecture" of Flow called "types-first". As far as I can tell, the only description is in this quote from the blog post:

"...it exploits full type annotations at file boundaries to perform better (more parallelizable and less redundant) separate compilation."

Is there more detail about this anywhere? Specifically, I'm wondering what these full annotations are: what are the new restrictions on source code and declaration files?

For example, is this allowed?

import { func } from "./other-module";
export const myNumber = func(num1, num2);

It's problematic in TypeScript, since the type of myNumber is impossible to resolve without knowing the type of func. Will the "types-first" re-architecture of Flow require users to write:

import { func } from "./other-module";
export const myNumber: number = func(num1, num2);

This is just one specific question I have. What I'm looking for is a little bit more information and a link to a document explaining all the known implications of the re-architecture.

like image 357
Max Heiber Avatar asked Apr 07 '20 11:04

Max Heiber


People also ask

What does the types-first architecture mean for flow?

TL;DR: The types-first architecture unlocks Flow’s potential at scale by leveraging fully typed module boundaries. We plan to migrate to the new architecture over the next months. Flow is designed to type check extremely large projects.

What are the three types of data flow architecture?

The workflow consists of a series of transformations on the input information, where information and operations are independent of each other. In this article we have discussed three Data flow architectures namely Batch Sequential, Pipe & filter, and Process Control architecture.

What is the difference between workflow and data flow architecture?

The workflow consists of a series of transformations on the input information, where information and transformation methods are independent of each other. In a data flow architecture, information is pulled into the system which then flows through several modules and goes through transformation until destination (output or a data store) is achieved.

What are the disadvantages of types-first architecture?

This architecture led to a variety of performance problems, including peak memory blowups, long garbage collection pauses, amplification of non-linear time complexity, and low use of parallelism. On the other hand, in types-first, w e compute the types of the upstream files directly, since module boundaries must have full type annotations.


Video Answer


1 Answers

It sounds really flashy and maybe it is under the hood. But in reality it's quite simple. In your code snippet you're absolutely correct, it pretty much means just that.

You must have an explicitly defined type before you export

Though not necessarily right before you export. The following works too.

const TestComponent = (): React.Node => {};

export default TestComponent;

It adds a little more overhead, but the benefits are:

  • improvements in performance because flow doesn't need to scan all dependencies before it can give you soundness checks
  • More reliable code because flow runs within module boundaries so you don't get flow errors that are caused by deeply nested dependencies.

They've also released a new blog post that goes into this further since types first have now been released officially. https://medium.com/flow-type/types-first-a-scalable-new-architecture-for-flow-3d8c7ba1d4eb

UPDATE The types-first architecture is now documented.

like image 178
Brianzchen Avatar answered Oct 16 '22 10:10

Brianzchen