Home >Web Front-end >JS Tutorial >Does `return await` Impact Performance Significantly?

Does `return await` Impact Performance Significantly?

DDD
DDDOriginal
2024-11-18 09:59:02687browse

Does `return await` Impact Performance Significantly?

Does return await Impact Performance?

Despite the eslint rule "no-return-await" suggesting that it introduces performance issues, this isn't entirely true.

The MDN documentation showcases an example of return await without highlighting any potential performance concerns.

Impact on Performance:

In reality, return await does not lead to a significant performance problem. It simply adds an unnecessary operation, making the execution slightly longer. It's comparable to the innocuous return x 0 for an integer x.

Why It's Considered Poor Practice:

Although return await doesn't harm performance, it's regarded as poor style. It indicates a lack of understanding of promises and async/await.

One Exception:

In the following scenario, return await makes a crucial difference:

try {
    …
    return await …;
} …

await catches rejections and ensures the promise resolution before executing catch or finally handlers. A plain return would have ignored this behavior.

The above is the detailed content of Does `return await` Impact Performance Significantly?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn