dreampiggy / dreampiggy.github.io

DreamPiggy's blog
MIT License
3 stars 1 forks source link

Swift 调试性能的优化方案 | 小猪的博客 #18

Open dreampiggy opened 2 years ago

dreampiggy commented 2 years ago

https://dreampiggy.com/2022/05/07/Swift-%E8%B0%83%E8%AF%95%E6%80%A7%E8%83%BD%E7%9A%84%E4%BC%98%E5%8C%96%E6%96%B9%E6%A1%88/

声明此篇文章预计5月中,发布于微信公众号《字节跳动终端技术》,原作者就是我,版权所有。在个人博客这里转发去掉了招聘相关的文案。如果需要也可以进行进一步交流(邮件或者GitHub)提供试用版工具链。 公众号链接: 背景通常来说,大型Swift项目常含有大量混编(Objc/C/C++甚至是Rust)代码,含有超过100个以上的Swift Module,并可能同时包含二进制部分和源码部分。而这种大型项目

dreampiggy commented 2 years ago

放一个工具链链接

yuzhouwww commented 2 years ago

公众号没有这篇啊

dreampiggy commented 2 years ago

@yuzhouwww 公众号没有这篇啊

先暂时屏蔽,等公众号和平台审核完毕,避免误判为自己抄袭自己:)

dreampiggy commented 2 years ago

备注: Xcode 13.3不建议禁用symbols.use-swift-dwarfimporter false,存在一个Bug导致,私有库的Objc类如UICTFont,会递归导致LLDB崩溃。已经修复在内部的工具链中,将预计在第二篇系列文章中解释原因

ishall1 commented 2 years ago

@dreampiggy 测试一下评论: 放一个神秘链接

这是你们使用的工具链吗?

hsuyelin commented 2 years ago

大佬,有针对Xcode13.4的工具链么,Xcode13.4无法真机调试,报错:

Unsupported Configuration The Swift standard library from the toolchain cannot be used on devices. Select a macOS or simulator run destination instead, or use a different toolchain that only provides the compiler.

dreampiggy commented 2 years ago

@hsuyelin 试试这个:5.6.1,和5.6相比变化不大

hsuyelin commented 2 years ago

感谢,我试试 ~ > @dreampiggy

@hsuyelin 试试这个:5.6.1,和5.6相比变化不大

hsuyelin commented 2 years ago

可以了,感谢 ~ > @dreampiggy

@hsuyelin 试试这个:5.6.1,和5.6相比变化不大

ianhwu commented 2 years ago

Xcode 13.3导致部分项目po提示Couldn’t realize type of self, 这个有解决方案了吗? WWDC 2022

dreampiggy commented 2 years ago

Xcode 13.3导致部分项目po提示Couldn’t realize type of self, 这个有解决方案了吗? WWDC 2022

使用上文的,5.6.1 toolchain

原因WWDC的Adrian提到过,是因为内置Swift编译器的参数和LLDB获取到的参数不一致,一般是因为你们预二进制的static archive Swiftmodule,没有最终通过-add_ast_path传给链接器,导致LLDB内置Swift编译器获取不到相关的Search Paths

我在修正版的LLDB中通过其他方式集成和获取了同样的参数,保证尽量Match二进制期间的参数,目前在飞书测试良好

ianhwu commented 2 years ago

@dreampiggy

Xcode 13.3导致部分项目po提示Couldn’t realize type of self, 这个有解决方案了吗? WWDC 2022

使用上文的,5.6.1 toolchain

原因WWDC的Adrian提到过,是因为内置Swift编译器的参数和LLDB获取到的参数不一致,一般是因为你们预二进制的static archive Swiftmodule,没有最终通过-add_ast_path传给链接器,导致LLDB内置Swift编译器获取不到相关的Search Paths

我在修正版的LLDB中通过其他方式集成和获取了同样的参数,保证尽量Match二进制期间的参数,目前在飞书测试良好

@dreampiggy

Xcode 13.3导致部分项目po提示Couldn’t realize type of self, 这个有解决方案了吗? WWDC 2022

使用上文的,5.6.1 toolchain

原因WWDC的Adrian提到过,是因为内置Swift编译器的参数和LLDB获取到的参数不一致,一般是因为你们预二进制的static archive Swiftmodule,没有最终通过-add_ast_path传给链接器,导致LLDB内置Swift编译器获取不到相关的Search Paths

我在修正版的LLDB中通过其他方式集成和获取了同样的参数,保证尽量Match二进制期间的参数,目前在飞书测试良好

thx

ianhwu commented 2 years ago

所以 Couldn’t realize type of self 这个问题会在官方 5.7 修复掉吗?

dreampiggy commented 2 years ago

@yansaid 目前5.7的LLDB代码中没有包括.

See: https://github.com/apple/llvm-project/pull/3353#issuecomment-1098666002

默认情况下,po的context下,Swift只会继承来主二进制(链接器参数-add_ast_path)的Module和serialize-debugging-options写入的Search Paths; 但是有时候跨机器和模块编译的Search Path是不同的;我在兼容模式下,会通过从当前po类型所在Module,找到之前通过的context,递归解析swiftmodule/interface得到的Search Paths,补全进来。代价是第一次稍微慢一点


其实最合理的修复建议是,保证每一个你们的swiftmodule static archive(比如,你们跨机器编译的,或者从某个第三方来的Swift静态库),全部塞到最终的链接器参数中

-Wl,-add_ast_path /path/to/libMyLib1.swiftmodule -Wl,-add_ast_path /path/to/libMyLib2.swiftmodule ...
fuyuxin666 commented 2 years ago

@hsuyelin 感谢,我试试 ~ > @dreampiggy

@hsuyelin 试试这个:5.6.1,和5.6相比变化不大

想问一下大佬怎么使用这个工具链呀

@dreampiggy @hsuyelin 试试这个:5.6.1,和5.6相比变化不大

Zhangyanshen commented 2 years ago

Message from debugger: The LLDB RPC server has crashed. You may need to manually terminate your process. The crash log is located in ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log.

老哥,用了你提供的这个工具一段时间后,一直报这个crash,这个是因为什么呢?

dreampiggy commented 2 years ago

Message from debugger: The LLDB RPC server has crashed. You may need to manually terminate your process. The crash log is located in ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log.

老哥,用了你提供的这个工具一段时间后,一直报这个crash,这个是因为什么呢?

完整堆栈发上来,~/Library/Logs/DiagnosticReports下的lldb-rpc-server进程,或者你用Console.app找

Zhangyanshen commented 2 years ago

Message from debugger: The LLDB RPC server has crashed. You may need to manually terminate your process. The crash log is located in ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log. 老哥,用了你提供的这个工具一段时间后,一直报这个crash,这个是因为什么呢?

完整堆栈发上来,~/Library/Logs/DiagnosticReports下的lldb-rpc-server进程,或者你用Console.app找

lldb-rpc-server-2022-09-05-141345.ips.zip

Zhangyanshen commented 2 years ago

Message from debugger: The LLDB RPC server has crashed. You may need to manually terminate your process. The crash log is located in ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log. 老哥,用了你提供的这个工具一段时间后,一直报这个crash,这个是因为什么呢?

完整堆栈发上来,~/Library/Logs/DiagnosticReports下的lldb-rpc-server进程,或者你用Console.app找

老哥,这个问题有帮忙看吗?

dreampiggy commented 2 years ago

Swift 5.7对应的工具链:https://lf3-client-infra.bytetos.com/obj/client-infra-images/lizhuoli/f7dac35688c54f2e9ac1a605b4295a39/2022-05-07/swift-5.7-2022-09-20-lldb_framework.tar.gz

使用方法:

  1. tar -xzf your_download_lldb_framework_path.tar.gz -C ~/
  2. Xcode选择Toolchains -> Xcode 14.0 (LLDB)
  3. 如果遇到报错可Command + Q重启再试
Zhangyanshen commented 2 years ago

Swift 5.7对应的工具链:https://lf3-client-infra.bytetos.com/obj/client-infra-images/lizhuoli/f7dac35688c54f2e9ac1a605b4295a39/2022-05-07/swift-5.7-2022-09-20-lldb_framework.tar.gz

使用方法:

  1. tar -xzf your_download_lldb_framework_path.tar.gz -C ~/
  2. Xcode选择Toolchains -> Xcode 14.0 (LLDB)
  3. 如果遇到报错可Command + Q重启再试

感谢老哥👍🏻

Zhangyanshen commented 2 years ago

Swift 5.7对应的工具链:https://lf3-client-infra.bytetos.com/obj/client-infra-images/lizhuoli/f7dac35688c54f2e9ac1a605b4295a39/2022-05-07/swift-5.7-2022-09-20-lldb_framework.tar.gz

使用方法:

  1. tar -xzf your_download_lldb_framework_path.tar.gz -C ~/
  2. Xcode选择Toolchains -> Xcode 14.0 (LLDB)
  3. 如果遇到报错可Command + Q重启再试

大佬,我今天试了一下,除了首次进入断点快了一些,po、p、v都没怎么快,之前提供的5.6.1的就快了很多

dreampiggy commented 2 years ago

少数settings的默认值修改过,一般无脑接入即可,不需要lldbinit修改

hsuyelin commented 1 year ago

大佬,有办法能让macos13.0使用xcode13.4么。虽然可以通过命令行方式打开,但是每次都用命令行很麻烦,有没有骚操作

Message ID: @.***>

SunXiangLong commented 1 year ago

xcode 15.0 巨慢有啥好解决办法么

dreampiggy commented 1 year ago

Swift 5.9已经做了一定的性能改动,另外现在po self.foobar已经会被翻译为 expr self.foobar并直接通过地址解析变量,而不是JIT,按理说效果应该会好很多。

https://www.swift.org/blog/whats-new-swift-debugging-5.9/

如果还有问题,后续再看是不是提供自定义编译的LLDB