Skip to content

Commit f69880c

Browse files
fix: Optimizes parsing of large non-UTF8 queries
While this doesn't impact UTF8 strings built up in Swift, Strings decoded from random data (like through Vapor, for example) may not be marked as UTF8, which makes the lexer UTF8 conversions very expensive. In evaluation of 450kb requests, performance improved from 27min to 5sec.
1 parent dda63e4 commit f69880c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/GraphQL/Language/Source.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
* but is mostly useful for clients who store GraphQL documents in
44
* source files; for example, if the GraphQL input is in a file Foo.graphql,
55
* it might be useful for name to be "Foo.graphql".
6+
*
7+
* Note that since Source parsing is heavily UTF8 dependent, the body
8+
* is converted into contiguous UTF8 bytes if necessary for optimal performance.
69
*/
710
public struct Source {
811
public let body: String
912
public let name: String
1013

1114
public init(body: String, name: String = "GraphQL") {
15+
var utf8Body = body
16+
utf8Body.makeContiguousUTF8()
17+
1218
self.body = body
1319
self.name = name
1420
}

0 commit comments

Comments
 (0)