Skip to content

Refactor: reduce compile time of common/chat.cpp #17329

@ngxson

Description

@ngxson

Background Description

Ref: #17324 (comment)

common/chat.cpp currently takes 20s to compile (measured on my macbook M3 max). This can be quite painful DX for those who want to contribute to the chat parsing system (tool calling / reasoning)

A quick test reveals that most of the time was spent to compile minja/chat-template.hpp. Removing it and replace the minja::chat_template with a stub implementation reduces the compile time to just 10s

Another test was to delete all of the common_chat_parse_* functions just to measure the impact. In this case, the compile time further reduced by 5s

Possible Refactor Approaches

One solution can be to move common_chat_parse_* either to a dedicated file, chat-templates.cpp, or to move to the existing chat-parser.cpp

This won't reduce the total compile time, but will provide a better DX, as most of the time whenever there is a new model that need to be supported, contributors need to modify code in common_chat_parse_*

Another solution is to split chat-template.hpp into header/implementation files. But this requires changing directly on the upstream project

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions