Get GenAI guide

Access HaxiTAG GenAI research content, trends and predictions.

Saturday, August 10, 2024

Accelerating Code Migrations with AI: Google’s Use of Generative AI in Code Migration

In recent years, the rapid development of software has led to the exponential growth of source code repositories. Google's monorepo is a prime example, containing billions of lines of code. To keep up with code changes, including language version updates, framework upgrades, and changes in APIs and data types, Google has implemented a series of complex infrastructures for large-scale code migrations. However, static analysis and simple migration scripts often struggle with complex code structures. To address this issue, Google has developed a new set of generative AI-driven tools that significantly enhance the efficiency and accuracy of code migrations.

Application of Generative AI Tools in Code Migration

Google has internally developed a new tool that combines multiple AI-driven tasks to assist developers in large-scale code migrations. The migration process can be summarized into three stages: targeting, edit generation and validation, and change review and rollout. Among these stages, generative AI shows the most significant advantage in the second stage of edit generation and validation.

Targeting

In the migration process, the first step is to identify the locations in the codebase that need modifications. By using static tools and human input, an initial set of files and locations is determined. The tool then automatically expands this set to include additional relevant files such as test files, interface files, and other dependencies.

Edit Generation and Validation

The edit generation and validation stage is the most challenging part of the process. Google uses a version of the Gemini model, fine-tuned on internal code and data, to generate and validate code changes. The model predicts the differences (diffs) in the files where changes are needed based on natural language instructions, ensuring the final code is correct.

Change Review and Rollout

Finally, the generated code changes undergo automatic validation, including compiling and running unit tests. For failed validations, the model attempts to automatically repair the issues. After multiple validations and scoring, the final changes are applied to the codebase.

Case Study: Migrating from 32-bit to 64-bit Integers

In Google's advertising system, ID types were initially defined as 32-bit integers. With the growth in the number of IDs, these 32-bit integers were on the verge of overflow. Therefore, Google decided to migrate these IDs to 64-bit integers. This migration process involved tens of thousands of code locations, requiring significant time and effort if done manually.

By using the AI migration tool, Google significantly accelerated the process. The tool can automatically generate and validate most code changes, greatly reducing manual operations and communication costs. It is estimated that the total migration time was reduced by 50%, with 80% of the code modifications generated by AI.

Future Directions

Looking ahead, Google plans to apply AI to more complex migration tasks, such as data exchanges across multiple components or system architecture changes. Additionally, there are plans to improve the migration user experience in IDEs, allowing developers greater flexibility in using existing tools.

The successful application of generative AI in code migration demonstrates its wide potential, extending beyond code migration to error correction and general code maintenance. This technology's ongoing development will significantly enhance software development efficiency and drive industry progress.

Through this exploration, Google not only showcased AI's powerful capabilities in code migration but also provided valuable insights and ideas for other enterprises and developers. The application of generative AI will undoubtedly lead the future direction of software development.

TAGS:

Google generative AI tools, AI-driven code migration, software development efficiency, large-scale code migration, Gemini model code validation, Google monorepo, 32-bit to 64-bit integer migration, AI in code maintenance, AI-powered code change validation, future of software development with AI

Related article

Unlocking New Productivity Driven by GenAI: 7 Key Areas for Enterprise Applications
Data-Driven Social Media Marketing: The New Era Led by Artificial Intelligence
HaxiTAG: Trusted Solutions for LLM and GenAI Applications
HaxiTAG Assists Businesses in Choosing the Perfect AI Market Research Tools
HaxiTAG Studio: AI-Driven Future Prediction Tool
HaxiTAG Studio: Leading the Future of Intelligent Prediction Tools
Organizational Transformation in the Era of Generative AI: Leading Innovation with HaxiTAG's Studio