Using absl::flat_hash_map in headers and build size

175 views
Skip to first unread message

David Roger

unread,
Apr 18, 2025, 10:58:42 AMApr 18
to bu...@chromium.org
Hello,

my CL is failing the compile-size step, and I don't know how to fix this.

I think this is because it adds includes to basl::flat_hash_map in header files?
(for example in components/sync/service/data_type_manager.h or sync_service.h)

The instructions recommend using forward declarations, but I don't think this is desirable for flat_hash_map, right?

I used flat_hash_map because it's the newly recommended map type, but I see that it's not used widely yet.

Any suggestions?

Thank you!

Greg Thompson

unread,
Apr 18, 2025, 11:23:30 AMApr 18
to David Roger, bu...@chromium.org
I hit the same thing in https://crrev.com/c/6335513. "Compile-Size: See commit description." w/ an explanation in the description seems appropriate to me.

--
You received this message because you are subscribed to the Google Groups "build" group.
To unsubscribe from this group and stop receiving emails from it, send an email to build+un...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/build/CAL3rL5hekm%2B%2BXsy_7m%3D8J%2BTaJh-7pBQgnjtEuffHGc%2BbHWkkYQ%40mail.gmail.com.

Junji Watanabe

unread,
Apr 21, 2025, 12:02:45 AMApr 21
to Greg Thompson, David Roger, bu...@chromium.org
As Greg suggested, you can skip the check if the compile size increase is not avoidable.

Takuto Ikuta (生田 拓人)

unread,
Apr 21, 2025, 12:29:50 AMApr 21
to David Roger, Greg Thompson, bu...@chromium.org, Junji Watanabe
I think some of your includes can be replaced with forward declaration?
and include could be replaced with
```
namespace absl {
template<class K, class V> class flat_hash_map;
}
```
?

You need to include header in cc files instead if you use forward declaration in header files.



--
Takuto Ikuta
Software Engineer in Tokyo
Chrome Ops (chrome browser build team)

Hans Wennborg

unread,
Apr 22, 2025, 7:45:38 AMApr 22
to Takuto Ikuta (生田 拓人), David Roger, Greg Thompson, bu...@chromium.org, Junji Watanabe
+1, You can forward declare flat_hash_map as Takuto showed.

I just skimmed the first couple of headers of your CL, and functions which return a flat_hash_map only need a forward declaration. I also saw some functions taking it by value as an argument. Perhaps those could be passed by const-ref instead.

The compile-time bot reported a 2.15 GB increase in input size, so it seems worth some effort if we can reduce that.

David Roger

unread,
Apr 22, 2025, 8:52:11 AMApr 22
to Hans Wennborg, Takuto Ikuta (生田 拓人), David Roger, Greg Thompson, bu...@chromium.org, Junji Watanabe
This does not work:

```
namespace absl {
template<class K, class V> class flat_hash_map;
}
```

The error is:
```
In file included from ../../components/sync/service/sync_service.h:23:
../../third_party/abseil-cpp/absl/container/flat_hash_map.h:130:1: error: too many template parameters in template redeclaration
  130 | template <class K, class V, class Hash = DefaultHashContainerHash<K>,
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  131 |           class Eq = DefaultHashContainerEq<K>,
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  132 |           class Allocator = std::allocator<std::pair<const K, V>>>
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../components/sync/service/data_type_manager.h:22:1: note: previous template declaration is here
   22 | template <class K, class V>
```

This is because flat_hash_map has actually 6 template arguments, but 4 of them have default values.

If we wanted to forward declare, I think we would need a file like this one:

Hans Wennborg

unread,
Apr 22, 2025, 9:06:38 AMApr 22
to David Roger, Takuto Ikuta (生田 拓人), Greg Thompson, bu...@chromium.org, Junji Watanabe
I suppose the Abseil folks aren't interested in providing a flat_hash_map_fwd.h header.

Oh well.
Reply all
Reply to author
Forward
0 new messages