Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPP: Make functions mostly noexcept to improve runtime performance #14613

Conversation

nonwill
Copy link
Contributor

@nonwill nonwill commented Feb 3, 2025

When exception caught in ClipperLib::ClipperOffset::Execute, just printf the what message to stderr and return false. When DBPostProcessor::UnClip failed in calling ClipperLib::ClipperOffset::Execute, just return (empty or null) cv::RotatedRect().

@nonwill nonwill changed the title Make functions mostly noexcept to improve runtime performance CPP: Make functions mostly noexcept to improve runtime performance Feb 3, 2025
Copy link

paddle-bot bot commented Feb 5, 2025

Thanks for your contribution!

@GreatV
Copy link
Collaborator

GreatV commented Feb 5, 2025

I wonder if you have tested this modification? Does it run smoothly on Windows, MacOS and Linux? Does it improve performance?

@nonwill
Copy link
Contributor Author

nonwill commented Feb 5, 2025

这个 pr 是 #14610 的后续补充,它们来自于学习并使用 PdddleOCR 过程的实践,具体代码在 https://github.com/nonwill/PdddleOCR -- 导出了个动态库以方便其它应用调用,阅读代码的过程中做了这些(pr)的修改。

Does it improve performance?

对于使用了 std::vector::emplace_back 的方法(函数),在明确没有异常抛出的情况下,编译时会有不同优化,运行时没有异常相关的处理,理论上分析会有性能提升,实际上性能的提升应该也是可以测量的,但提升程度依赖于编译器的优化工作。

我这里的使用场景(对屏幕划词 -- 小范围截屏并 OCR)很单一,OCR 图片都很小,一次仅处理一个图片,加上个人电脑配置还是十几年前的老旧硬件,所以体验上对性能的感知并不明显。

I wonder if you have tested this modification? Does it run smoothly on Windows, MacOS and Linux?

Linux 还没来得及测试,MacOS 没有真机环境,当前仅在安装有 Windows 系统的个人笔记本中做了测试,demo (编译自deploy\cpp_infer\src\main.cpp) 运行没有问题。这个 pr 除了 ClipperLib::ClipperOffset::Execute 对可能抛出的异常的捕获处理外,并没有其它程序执行逻辑上的改动,noexcept 也不会改变本来就无异常抛出的函数的逻辑,所以修改后的代码在其它平台上应该也能正常编译和运行。

说到测试,毕竟不是每个人都有或了解 Linux 或 Unix 环境,建议为 PdddleOCR 的 C++ 代码部分增加测试用例。或者简单些,针对生成的 ppocr(.exe) 进行测试都行。这样提交 pr 后,除了 code-style 等的检查,还可以通过 Action 在 Linux 和 macOS 系统中编译 ppocr(.exe) 并作简单的 ocr 测试来验证程序逻辑的正确性。

Copy link
Collaborator

@GreatV GreatV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GreatV GreatV merged commit ea71030 into PaddlePaddle:main Feb 5, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants