如何在代码存储库中提高代码辅助的性能?



Code Assist非常慢,需要长达一个小时的时间来解析环境。我该如何提高性能呢?

简短的回答:如果过去7天没有提交,则环境缓存(由Code Assist使用)可能已经过期。

执行一个提交操作,让CI重新计算环境缓存。长答案:当使用python转换时,需要计算一个有效的python环境,该环境满足所有所需的包及其依赖项。环境需要的python包越多,它们的版本也越具体,解决这个问题就越困难(也就越长)。对于这个特定的代码存储库,这里是元数据中所需设置的所有python包和版本。yaml文件:

# If you need to modify the runtime requirements for your package,
# update the 'requirements.run' section in this file
package:
name: "{{ PACKAGE_NAME }}"
version: "{{ PACKAGE_VERSION }}"
source:
path: ../src
requirements:
build:
- python 3.6.*
- setuptools
- unionutils 0.0.39
- palantirutils 0.1.100
# Any extra packages required to run your package.
run:
- python 3.6.*
- transforms {{ PYTHON_TRANSFORMS_VERSION }}
- unionutils 0.0.39
- palantirutils 0.1.100
- transforms-expectations
build:
script: python setup.py install --single-version-externally-managed --record=record.txt

实际上,这些包都有自己的依赖关系,所以这个repo的解析环境实际上需要更多不同版本的python包(你可以在conda lock文件中看到这些,它是repo中的一个隐藏文件)。在这个例子中,有123个额外的依赖项。

1. # This file is autogenerated and supposed to be committed to the git repository.
2. # Changing this file is not recommended and will likely break the build.
3. # Run `./gradlew --write-locks` to regenerate.
4. _libgcc_mutex=0.1=conda_forge @ linux-64
5. _openmp_mutex=4.5=2_gnu @ linux-64
6. alsa-lib=1.2.7.2=h166bdaf_0 @ linux-64
7. brotlipy=0.7.0=py36h27cfd23_1003 @ linux-64
8. ca-certificates=2022.12.7=ha878542_0 @ linux-64
9. certifi=2021.5.30=py36h5fab9bb_0 @ linux-64
10. cffi=1.14.6=py36hd8eec40_1 @ linux-64
11. charset-normalizer=2.1.1=pyhd8ed1ab_0 @ noarch
12. cryptography=35.0.0=py36hd23ed53_0 @ linux-64
13. cycler=0.11.0=pyhd8ed1ab_0 @ noarch
14. dbus=1.13.18=hb2f20db_0 @ linux-64
15. decorator=5.1.1=pyhd3eb1b0_0 @ noarch
16. expat=2.5.0=h27087fc_0 @ linux-64
17. font-ttf-dejavu-sans-mono=2.37=h6964260_0 @ noarch
18. font-ttf-inconsolata=3.000=h77eed37_0 @ noarch
19. font-ttf-source-code-pro=2.038=h77eed37_0 @ noarch
20. font-ttf-ubuntu=0.83=h8b1ccd4_0 @ noarch
21. fontconfig=2.14.1=hc2a2eb6_0 @ linux-64
22. fonts-anaconda=1=h8fa9717_0 @ noarch
23. fonts-conda-ecosystem=1=hd3eb1b0_0 @ noarch
24. freetype=2.12.1=hca18f0e_1 @ linux-64
25. freezegun=1.2.2=pyhd8ed1ab_0 @ noarch
26. future=0.18.2=py36h5fab9bb_3 @ linux-64
27. gettext=0.21.1=h27087fc_0 @ linux-64
28. glib-tools=2.72.1=h6239696_0 @ linux-64
29. glib=2.72.1=h6239696_0 @ linux-64
30. gst-plugins-base=1.20.3=h57caac4_2 @ linux-64
31. gstreamer=1.20.3=hd4edc92_2 @ linux-64
32. icu=69.1=h9c3ff4c_0 @ linux-64
33. idna=3.4=pyhd8ed1ab_0 @ noarch
34. jpeg=9e=h166bdaf_2 @ linux-64
35. keyutils=1.6.1=h166bdaf_0 @ linux-64
36. kiwisolver=1.3.1=py36h605e78d_1 @ linux-64
37. krb5=1.20.1=hf9c8cef_0 @ linux-64
38. lcms2=2.14=hfd0df8a_1 @ linux-64
39. ld_impl_linux-64=2.39=hcc3a1bd_1 @ linux-64
40. lerc=4.0.0=h27087fc_0 @ linux-64
41. libblas=3.9.0=16_linux64_openblas @ linux-64
42. libcblas=3.9.0=16_linux64_openblas @ linux-64
43. libclang=13.0.1=default_hc23dcda_0 @ linux-64
44. libdeflate=1.14=h166bdaf_0 @ linux-64
45. libedit=3.1.20210714=h7f8727e_0 @ linux-64
46. libevent=2.1.10=h9b69904_4 @ linux-64
47. libffi=3.4.2=h6a678d5_6 @ linux-64
48. libgcc-ng=12.1.0=h8d9b700_17 @ linux-64
49. libgfortran-ng=12.2.0=h69a702a_19 @ linux-64
50. libgfortran5=12.2.0=h337968e_19 @ linux-64
51. libglib=2.72.1=h2d90d5f_0 @ linux-64
52. libgomp=12.1.0=h8d9b700_17 @ linux-64
53. libiconv=1.16=h516909a_0 @ linux-64
54. liblapack=3.9.0=16_linux64_openblas @ linux-64
55. libllvm13=13.0.1=hf817b99_2 @ linux-64
56. libnsl=2.0.0=h7f98852_0 @ linux-64
57. libogg=1.3.5=h27cfd23_1 @ linux-64
58. libopenblas=0.3.21=pthreads_h78a6416_3 @ linux-64
59. libopus=1.3.1=h7f98852_1 @ linux-64
60. libpng=1.6.39=h753d276_0 @ linux-64
61. libpq=14.5=h2baec63_4 @ linux-64
62. libsqlite=3.40.0=h753d276_0 @ linux-64
63. libstdcxx-ng=12.1.0=ha89aaad_17 @ linux-64
64. libtiff=4.5.0=h82bc61c_0 @ linux-64
65. libuuid=2.32.1=h14c3975_1000 @ linux-64
66. libvorbis=1.3.7=he1b5a44_0 @ linux-64
67. libwebp-base=1.2.4=h166bdaf_0 @ linux-64
68. libxcb=1.13=h7f98852_1004 @ linux-64
69. libxkbcommon=1.0.3=he3ba5ed_0 @ linux-64
70. libxml2=2.9.12=h885dcf4_1 @ linux-64
71. libzlib=1.2.13=h166bdaf_4 @ linux-64
72. lz4-c=1.9.3=h295c915_1 @ linux-64
73. matplotlib-base=3.3.4=py36hd391965_0 @ linux-64
74. matplotlib=3.3.4=py36h5fab9bb_0 @ linux-64
75. mysql-common=8.0.31=haf5c9bc_0 @ linux-64
76. mysql-libs=8.0.31=h28c427c_0 @ linux-64
77. ncurses=6.2=h58526e2_4 @ linux-64
78. nspr=4.35=h27087fc_0 @ linux-64
79. nss=3.82=he02c5a1_0 @ linux-64
80. numpy=1.19.5=py36hfc0c790_2 @ linux-64
81. olefile=0.46=pyh9f0ad1d_1 @ noarch
82. openjpeg=2.4.0=hb52868f_1 @ linux-64
83. openssl=1.1.1=h7b6447c_0 @ linux-64
84. palantir-spark-time=3.15.0=py_0 @ noarch
85. palantirutils=0.1.100=py36_0 @ linux-64
86. pandas=1.1.5=py36ha9443f7_0 @ linux-64
87. pcre=8.45=h9c3ff4c_0 @ linux-64
88. pillow=8.3.2=py36h676a545_0 @ linux-64
89. pip=22.0.2=pyhd8ed1ab_0 @ noarch
90. pthread-stubs=0.4=h36c2ea0_1001 @ linux-64
91. py4j=0.10.9.7=pyhd8ed1ab_0 @ noarch
92. pycparser=2.21=pyhd3eb1b0_0 @ noarch
93. pydicom=2.3.1=pyh1a96a4e_0 @ noarch
94. pyopenssl=22.0.0=pyhd8ed1ab_1 @ noarch
95. pyparsing=3.0.9=pyhd8ed1ab_0 @ noarch
96. pyqt-impl=5.12.3=py36h7ec31b9_7 @ linux-64
97. pyqt5-sip=4.19.18=py36hc4f0c31_7 @ linux-64
98. pyqt=5.12.3=py36h5fab9bb_7 @ linux-64
99. pyqtchart=5.12=py36h7ec31b9_7 @ linux-64
100. pyqtwebengine=5.12.1=py36h7ec31b9_7 @ linux-64
101. pysocks=1.7.1=py36h5fab9bb_3 @ linux-64
102. pyspark-src=3.2.1_palantir.30=py_0 @ noarch
103. pyspark=3.2.1_palantir.30=py_0 @ noarch
104. python-dateutil=2.8.2=pyhd3eb1b0_0 @ noarch
105. python=3.6.15=hb7a2778_0_cpython @ linux-64
106. python_abi=3.6=2_cp36m @ linux-64
107. pytz=2022.7=pyhd8ed1ab_0 @ noarch
108. qt=5.12.9=h1304e3e_6 @ linux-64
109. readline=8.1=h27cfd23_0 @ linux-64
110. requests=2.28.1=pyhd8ed1ab_0 @ noarch
111. sas7bdat=2.2.3=pyhd8ed1ab_0 @ noarch
112. setuptools=58.0.4=py36h5fab9bb_2 @ linux-64
113. six=1.16.0=pyhd3eb1b0_1 @ noarch
114. sqlite=3.40.0=h5082296_0 @ linux-64
115. tk=8.6.12=h27826a3_0 @ linux-64
116. tornado=6.1=py36h8f6f2f9_1 @ linux-64
117. transforms-expectations=0.153.0=py_0 @ noarch
118. transforms=1.575.0=py_0 @ noarch
119. unionutils=0.0.39=py36_0 @ linux-64
120. urllib3=1.26.13=pyhd8ed1ab_0 @ noarch
121. wheel=0.37.1=pyhd3eb1b0_0 @ noarch
122. xorg-libxau=1.0.9=h7f98852_0 @ linux-64
123. xorg-libxdmcp=1.1.3=h516909a_0 @ linux-64
124. xz=5.2.9=h166bdaf_0 @ linux-64
125. zlib=1.2.13=h166bdaf_4 @ linux-64
126. zstd=1.5.2=h8a70e8d_4 @ linux-64
[Conda lock version]
v2 - fc1db1a3046b71820e26b48a2910180bd17d802db0610c30351282a31083fe9b

当第一次提交到一个新的python仓库时,在持续集成(CI)检查期间会发生两个相关的任务。第一个任务通过计算满足repo的所有依赖项和要求的包组合来解决python环境,第二个任务然后下载这些特定的包版本。这个已解析的环境记录在隐藏的conda锁文件中,有效期为7天(本质上是缓存的)。

任何时候在环境解决后的7天内进行新的提交时,CI检查可以使用缓存的python环境来跳过解决环境和下载包这两个任务,这大大加快了CI检查时间。

但是,如果提交是在缓存过期7天后进行的,或者如果提交更改了元数据中所需的python包或版本。然后需要再次解决环境问题,这将导致更长的CI时间。

那么这与代码辅助有什么关系呢?

代码辅助本质上需要运行相同的任务,但也可以从缓存文件中读取。因此,如果您注意到代码辅助需要很长时间才能运行,那是因为它无法从缓存中读取数据(要么是因为包更改,要么是因为缓存过期),而是必须解决环境本身的问题。但是,由于代码辅助不允许将代码写入存储库,因此在完成求解后无法修改缓存。

所以在这种情况下,我建议对repo的代码进行提交以重置缓存,然后你应该注意到代码辅助启动比40分钟快得多(直到7天的缓存过期或包更改)。

最新更新