Google Ads rebuilds itself with AI – Code migration

Google's Ads team has solved a number of migration tasks with AI and reports on its experiences in a paper: Some things work better without AI.

listen Print view
Google Ads

(Image: PixieMe/Shutterstock.com)

5 min. read
Contents

In a scientific paper, the Google Ads team describes how it used artificial intelligence to handle four migration tasks from old to modern code: switching from 32-bit IDs to 64-bit, updating JUnit3 to version 4, switching the time format from Joda to java.time and cleaning up unused sample code in all repositories.

According to the paper, the team was able to record a gain in time and effort of around fifty percent across all tasks. The benefit in terms of pure code was higher, but this was offset by the increased effort required for testing.

There are over 500 million lines of code in the Google Ads repositories that the team had to revise. The AI model used was Gemini, but in a version tailored to the tasks. This means that it was trained with the Google repositories and had to make changes across all sources. The problem with all the tasks was the high variance of the places to be changed.

Not only AI was used, but also traditional methods such as Abstract Syntax Trees (AST), heuristics and searches with regular expressions. ASTs were primarily used to find the places that needed to be changed. The change itself was then carried out by the LLM. The human check at the end was carried out as with every code change.

The rules for prompting contained general instructions for the task and then more specific sub-steps. These were interchangeable depending on the use case. The team found it helpful to ask the AI which of its suggested changes was the best.

Videos by heise

Google Ads uses IDs for users, merchants, campaigns, etc., which are available in C++ or Java, but not as independent types, but often as integers, sometimes even as text. The change from 32-bit to 64-bit affected "tens of thousands of places" including all class interfaces. The compilation of the relevant files was carried out by AST, the change itself by the AI. However, the Google team only let the AI loose on the parts of the code that could be checked by unit tests. The team had to adapt these for this purpose.

The human review passed eighty percent of the parts changed by the LLM as correct. In the case of the errors, the AI had usually changed too much. One prompt example reads:

{id} should be of type int64_t.
Update the tests to reflect a large id.
Initialize the {id}s with values larger than 10000000000.
If necessary add new test parameters with large ids.
If previous id was negative, new value should be negative.

It instructs the AI to adjust only the class constructor in which the type is to be changed. As a result, the LLM has also correctly corrected the private field and the use within the class. The following images show the changes in the diff and test file.

Diff shows the changes that the AI has completed correctly.

(Image: Google)

The test also shows the correct changes to the AI.

(Image: Google)

Similar experiences were made with the other projects. The change from the old Joda library to the java.time package was complicated by the fact that not all types are comparable, for example the standard Java time API has no counterpart to joda.time.Interval. Changes therefore require an intervention in the logic of the function. Here, the authors of the paper have to admit: "The migration is still ongoing and we are facing challenges to solve it".

In conclusion, the paper states that the best migration path is a mix of old and new methods. "We found that the planning capabilities of LLMs were not necessary and added a layer of complexity that should be avoided if possible." ASTs have the advantage of always being correct. AST parsers are also suitable for checking the modified code.

The team recommends using small, customized models. "They increase the reliability of the results and reduce the effort required for debugging." Human testing can become a bottleneck, as specialists are required for this. In future, this can be avoided by using better tools – Keyword: agents. The paper does not elaborate on this point.

The paper also states: "Whether it has an impact on quality in the long term needs to be observed." Overall, however, Google is planning to further expand AI migration in the ads sector.

(who)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.