GithubHelp home page GithubHelp logo

Comments (1)

astreet avatar astreet commented on April 28, 2024

Sorry this has taken a while, I wrote a long answer but it didn't cover everything I wanted so ended up putting it on the backlog, and well... 18 days later.

First-off, I'd recommend folks evaluate the two for themselves to see which meets their needs for product quality, perf, devx, integration with existing code (if applicable), etc: that's going to give a clearer picture most relevant to their specific context than anything I'll write below.

Second, both frameworks are moving targets due to both being under active development, so who knows how long much of the below will stay accurate after posting :)

As far as similarities go, both are declarative UI frameworks in which you write Comp(onents|omposables) which are effectively special static functions which should have no direct side effects while executing. They both 'resolve' down to some primitives - Views/Drawables in Litho and drawing commands in Compose for Android (I believe!). Both introduce a new way of thinking about writing UI, which solves many problems (e.g. bugs in managing UI state) and introduce fun new ones ('why is this update recreating so much of the tree?').

Both frameworks take React as a degree of inspiration, and have many of the same concepts (though litho uses the React names still): e.g. useEffect in Litho and SideEffect in Compose exist to accomplish approximately the same thing - in the same way I think someone wrote a cheatsheet for React/Compose, you could write one for many concepts between Litho/Compose. I'm not trying to say the APIs are interchangeable though - Compose has made some very cool innovations on things like gesture handling, composable functions with and without return, @composable modifiers, etc.

At time of writing, some of the main differences I see are:

  • On the core API front: Litho's Kotlin API is currently implemented without codegen or compiler plugins - it's plain old Kotlin code you can go read and step through in the debugger. Compose's semantics are realized via a compiler plugin can allow it to enforce some constraints and do some very clever things for fast updates, among other things, at the tradeoff of a bit more magic.
  • A main selling point of Litho (Kotlin and Java) is performance: this comes from granular (per view/drawable type) recycling, view flattening (removal of layout-only views), incremental mount (views/drawables are only materialized as they enter the viewport, with more granularity than RecyclerView), and background/ahead of time layout. This latter one imposes restrictions on code used from Litho (it must be threadsafe!) but has shown to improve scrolling, interactions and navigation. I know less about analogous optimizations in Compose, but currently composition/recomposition happens on the main thread: however I believe the team is currently working on adding parallel/ahead of time layout.
  • Beyond initial rendering, Compose is able to perform very granular updates in response to data changes via read tracking: Litho doesn't have this and generally gets by with coarser update boundaries, bridging out the Views/Drawables when necessary, and the use of DynamicProps and a Transitions API for animations.
  • Compose encompasses a larger ecosystem, across multiple libraries: for instance, at the moment Litho Kotlin doesn't publicly provide APIs around navigation, material design, alternate layout systems (Litho is flexbox or bust atm, but hopefully changing soon), or a data system (snapshot state). Compose also is being positioned to target Desktop, KMP, and web (though I can't speak to the state of those myself)
  • Compose inspection and tooling lives in Android Studio, Litho's is with Flipper (fbflipper.com)
  • Litho Kotlin components are fully compatible with our Spec-generated (Java) components: not super relevant to new adopters but important for incremental migration of the API.

In some ways this is just scratching the surface, but I think it covers the broad strokes. I'll end with saying that Compose is a really amazing set of libraries built by some very clever people, so major props to the team at Google!

from litho.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.