Skip to content

Add ABSL to flutter/engine #134741

Open
Open

Description

@gaaclarke

The Google C++ style guide recommends the usage of absl in many cases but we do not have it available in the flutter engine. In some cases this has caused us to duplicate and maintain similar functionality in fml (example: fml::SharedMutex and fml::Status), in other cases it has hurt our designs (example: IsValid() methods in impeller instead of using absl::status_or).

@zanderso has made a good point that we should be careful about binary size. This could be a problem especially if we use absl's offerings simultaneously with fml offerings which is complicated by the upfront cost to migrate existing code.

Chromium has already adopted absl so it should be easy to drop in technically.

There may some functionality in absl that doesn't exist today that could help us too. I don't have experience with absl::GetStackTrace, but just the other day a user was asking for stacktraces when debugging c++ asserts. If that works on any of our target platforms that could save us some debugging time too if FML_CHECK's print out the stacktrace in debug builds. I didn't explore more potential usages since what I've listed already seems valuable enough.

cc @matanlurey

Activity

  1. added
    engineflutter/engine related. See also e: labels.
    c: proposalA detailed proposal for a change to Flutter
    on Sep 14, 2023
  2. matanlurey commented on Sep 14, 2023

    @matanlurey
    Contributor

    Very supportive!

    I suspect if e increase base binary size by:

    • XXX%: it won't land, and we should engage the absl team to see if that's expected
    • XX% but if removing FML would buy us back most of it, we should still do it
    • X%, we should just do it
  3. johnmccutchan commented on Sep 14, 2023

    @johnmccutchan
    Contributor

    Some other benefits of absl:

    • very efficient maps and sets
    • call_once
    • absl::string_view
    • absl::Span (generalized readonly view of array)

    I think if we adopted absl we should drop FML as there is a lot of overlap

  4. zanderso commented on Sep 14, 2023

    @zanderso
    Member

    We DEPS it in https://github.com/flutter/engine/blob/main/DEPS#L640, but I'm not sure where it's currently used.

    There's a danger in doing any kind of gradual migration in that we won't be able to attribute binary size increases to it without proactive investigation (which may occur too late to do anything about it). I'm interested in thoughts on how to mitigate that. As a straw man, maybe some macros or typedefs could select between std:: maps/sets and absl:: maps/sets ?

  5. chinmaygarde commented on Sep 14, 2023

    @chinmaygarde
    Contributor

    We are already using Abseil. Among other things, for backtraces. So far, we have preferred libc++ then base. Abseil was open sourced after Flutter was using FML/FXL but the use case seems similar to base. Not sure we can get rid of base altogether.

    Since we have already deps it in, is there anything to do with this issue?

  6. matanlurey commented on Sep 14, 2023

    @matanlurey
    Contributor

    @chinmaygarde:

    We are already using Abseil. Among other things, for backtraces.

    @zanderso, if that's the case ^, then it's already part of our binary and I think as long as we remove the FML constructs as we migrate, it shouldn't be a problem? Alternatively we could do it one symbol/class/method at a time and do binary size snapshot checks if we're super concerned.

    ABSL itself might have data on how large they are.

  7. zanderso commented on Sep 14, 2023

    @zanderso
    Member

    @zanderso, if that's the case ^, then it's already part of our binary and I think as long as we remove the FML constructs as we migrate, it shouldn't be a problem?

    Since we link with linker GC/tree-shaking, the current binary size includes only the bits we use. If we use more of absl, linker gc will gc less stuff. There's a separate incremental cost when applying templates e.g. maps/sets to more types. That is, there isn't just a one-time fixed cost, but rather an incremental cost each time a templated class is applied to new template arguments. The templates are generative.

  8. gaaclarke commented on Sep 14, 2023

    @gaaclarke
    MemberAuthor

    Since we have already deps it in, is there anything to do with this issue?

    Do we need an autoroller? We should have at least established guidance on when and how to use it since there is some concern about using it without forethought with respect to binary size.

  9. chinmaygarde commented on Sep 14, 2023

    @chinmaygarde
    Contributor

    The style guide doesn't recommend Abseil. But it does mention Abseil in its examples and some of the constructs are really useful and I wish we had this available since inception. Having said that, IMO we should use Abseil constructs if:

    1. These are not available in libc++.
    2. There are not available in FML.
    3. The performance characteristics are measurably better than either of the above.

    We have a lot of code to migrate in hard to reach places (like Fuchsia) that a complete removal of FML is going to be a yak shave that seems too daunting for the gains. And having a mix of libc++, FML, and absl constructs is confusing in itself.

  10. matanlurey commented on Sep 14, 2023

    @matanlurey
    Contributor

    Ostensibly we're removing some of those pieces of code in the next year.

    Definitely not suggesting "let's do it next quarter", but should we maintain FML instead of using ABSL? Absolutely not, IMO.

  11. gaaclarke commented on Sep 15, 2023

    @gaaclarke
    MemberAuthor

    absl can't be freely used today for 2 minor reasons:

    1. their include structure is incompatible with ours
    2. it hasn't been updated in a long time and has deprecated function calls like __has_trivial_assign

    I'll take a quick stab at making it shipshape.

  12. gaaclarke commented on Sep 15, 2023

    @gaaclarke
    MemberAuthor

    Fixing the include structure is easy, the deprecation errors are not easy to get rid of though. I tried merging upstream to see if they were fixed there, but they weren't. I tried to start migrating the deprecated builtin functions, but I started getting weird static assertions like:

    ../../third_party/abseil-cpp/absl/base/internal/endian.h:246:37: error: no matching function for call to 'bit_cast'
      246 |   return bit_cast<int32_t>(ToHost32(bit_cast<uint32_t>(x)));
          |                                     ^~~~~~~~~~~~~~~~~~
    ../../third_party/abseil-cpp/absl/base/casts.h:163:23: note: candidate template ignored: requirement 'type_traits_internal::is_trivially_copyable<int>::value' was not satisfied [with Dest = uint32_t, Source = int32_t]
    

    int32_t definitely should be trivially copyable.

    It got involved enough that I decided to drop it until we have a clear case driving the change. Worse case scenario we can push and pop pragmas to disable the deprecation errors around the includes. But I don't imagine people will be happy with that. There is a bit of a catch 22 where people won't use absl::StatusOr because it isn't readily available but we won't add absl::StatusOr until it's used.

  13. added
    P2Important issues not at the top of the work list
    on Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions