Merged
Conversation
Collaborator
Author
|
同じ処理をしていたことがわかったので、次のようなキャッシュ層をいれると2倍くらいの速さになった diff --git a/Sources/CodableToTypeScript/Generator/PackageGenerator.swift b/Sources/CodableToTypeScript/Generator/Packa>
index a81d197..f0d4c2b 100644
--- a/Sources/CodableToTypeScript/Generator/PackageGenerator.swift
+++ b/Sources/CodableToTypeScript/Generator/PackageGenerator.swift
@@ -53,6 +53,7 @@ public final class PackageGenerator {
)
var symbolToSource: [String: SourceFile] = [:]
+ var convertedTSSources: [SourceFile: TSSourceFile] = [:]
// collect symbols included in for each swift source file
for module in context.modules.filter({ $0 !== context.swiftModule }) {
@@ -60,6 +61,7 @@ public final class PackageGenerator {
guard let tsSource = try? codeGenerator.convert(source: source) else {
continue
}
+ convertedTSSources[source] = tsSource
for declaredName in tsSource.memberDeclaredNames {
symbolToSource[declaredName] = source
}
@@ -84,7 +86,7 @@ public final class PackageGenerator {
while let source = targetSources.popLast() {
generatedSources.insert(source)
collect(at: source.file.lastPathComponent) {
- let tsSource = try codeGenerator.convert(source: source)
+ let tsSource = try convertedTSSources[source] ?? (codeGenerator.convert(source: source))
let entry = PackageEntry(
file: try tsPath(module: source.module, file: source.file),
~ |
omochi
approved these changes
Apr 26, 2024
Owner
omochi
left a comment
There was a problem hiding this comment.
なるほど。
結果的にcodeConverterの上層APIだけで済むようになってるのも良いですね。
| continue | ||
| } | ||
| convertedSources[source] = tsSource | ||
| for declaredName in tsSource.memberDeclaredNames { |
| return name == "AbsoluteURL" | ||
| }) | ||
| }) | ||
| XCTAssertFalse(hasTSAbsoluteURL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
機能的な変更ではなく、リファクタリングの意味合いの修正です。
#118 で導入されたPackageGeneratorのシンボル収集プロセスについてです。
ソースコードの変換処理はファイル単位で行われており、ファイル単位での成功と失敗があります。
ここでシンボル収集する際に、変換に失敗するファイルに含まれたシンボルは、結果的には参照できないので収集する必要がありません。
既存の実装は、ファイル内に含まれるSwift型1つずつについてシンボル収集するロジックになっていました。
これを、実際の変換処理に合わせてファイル単位の処理に書き換えます。
中の処理を展開するとやっていることは全く同じなので、機能的な変化はありません。
codeGenerator.convertの呼び出しが2箇所になって、同じ処理をしていることがわかりやすくなりました。ついでにこの問題に気づくきっかけになったテストを追加しています。