---
title: "What is the importance of inlining in query optimisation?"  
description: "What is the importance of inlining in query optimisation?"  
author: "Steilla Mitchel"  
published: 2023-07-30  
updated: 2023-07-31  
canonical: https://www.mindstick.com/forum/159378/what-is-the-importance-of-inlining-in-query-optimisation  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# What is the importance of inlining in query optimisation?

What is the [importance](https://www.mindstick.com/articles/13099/the-importance-of-machine-learning-service-providers) of inlining in [query optimization](https://www.mindstick.com/forum/160279/what-are-the-benefits-of-using-indexed-views-for-query-optimization)?

## Replies

### Reply by Aryan Kumar

Inlining is a compiler [optimization](https://yourviews.mindstick.com/view/85459/what-is-conversion-rate-optimization-and-how-to-get-started) technique that replaces a function call with the body of the function. This can improve the performance of a [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) by reducing the number of function calls that need to be executed.

There are two main benefits of inlining:

- **Reduced function call overhead:** When a function is called, the compiler has to create a new stack frame and copy the function's arguments into memory. This can be a performance bottleneck, especially for small functions. Inlining eliminates the need to create a new stack frame, which can improve performance.
- **Improved instruction cache locality:** When a function is inlined, the compiler can often place the instructions for the function in the same cache line as the instructions for the calling function. This can improve performance by reducing the number of cache misses that occur.

However, there are also some potential drawbacks to inlining:

- **Increased code size:** Inlining can increase the size of the compiled code, which can make it more difficult to load and execute the code.
- **Reduced code readability:** Inlining can make the code less readable, which can make it more difficult to debug and maintain.

Overall, inlining can be a valuable optimization technique for improving the performance of queries. However, it is important to weigh the benefits and drawbacks of inlining before deciding whether to use it.

Here are some examples of when inlining can be beneficial:

- When the function is small and frequently called.
- When the function is hot code, meaning that it is executed a lot.
- When the function is performance-critical.

Here are some examples of when inlining can be harmful:

- When the function is large or complex.
- When the function is not frequently called.
- When the function is not performance-critical.

Ultimately, the decision of whether or not to inline a function is a trade-off between performance and code size/readability.


---

Original Source: https://www.mindstick.com/forum/159378/what-is-the-importance-of-inlining-in-query-optimisation

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
