[webkit-dev] Compile times and class-scoped enums

Jer Noble jer.noble at apple.com
Fri Jan 20 09:50:05 PST 2023

Hi all!

I’ve noticed that compile times for the WebKit project have started creeping up again, so I and a few other WebKit contributors started looking into possible compile time improvements using the tools listed in <https://trac.webkit.org/wiki/AnalyzingBuildPerformance>. One cause of long compile times is when a commonly-included header (like Document.h) includes other headers (which include other headers, ad nauseam). Whereas much of the time those includes can be avoided by forward declaring types, for types (specifically enums) scoped within classes, this is impossible.

I attempted to address this in <https://github.com/WebKit/WebKit/pull/8867>, which (on this machine) reduces the total compile time of Document.h in the WebCore project from about 1000s to about 200s.

However, this change requires moving class-scoped enums out into the namespace scope. E.g.:

> diff --git a/Source/WebCore/Modules/audiosession/DOMAudioSession.h b/Source/WebCore/Modules/audiosession/DOMAudioSession.h
> index 01bf6960d3a4..d84e1eae78d5 100644
> --- a/Source/WebCore/Modules/audiosession/DOMAudioSession.h
> +++ b/Source/WebCore/Modules/audiosession/DOMAudioSession.h
> @@ -36,14 +36,17 @@
>  namespace WebCore {
> +enum class DOMAudioSessionType : uint8_t { Auto, Playback, Transient, TransientSolo, Ambient, PlayAndRecord };
> +enum class DOMAudioSessionState : uint8_t { Inactive, Active, Interrupted };
> +
>  class DOMAudioSession final : public RefCounted<DOMAudioSession>, public ActiveDOMObject, public EventTarget, public AudioSession::InterruptionObserver {
>  public:
>      static Ref<DOMAudioSession> create(ScriptExecutionContext*);
>      ~DOMAudioSession();
> -    enum class Type : uint8_t { Auto, Playback, Transient, TransientSolo, Ambient, PlayAndRecord };
> -    enum class State : uint8_t { Inactive, Active, Interrupted };
> +    using Type = DOMAudioSessionType;
> +    using State = DOMAudioSessionState;
>      ExceptionOr<void> setType(Type);
>      Type type() const;

So that these enums can be forward declared in Document.h, rather than including the header wholesale.

However, this requires a significant coding style change, both to existing code and new code, and as such, it should probably be discussed here. So, what do people think? Is the change in coding style (moving class-scoped enums out into namespace scope) worth doing if it means a significant increases in compile speeds?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20230120/67522f8e/attachment.htm>

More information about the webkit-dev mailing list