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

Implement JSString to reduce bridging overhead #63

Merged
merged 2 commits into from
Sep 18, 2020
Merged

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Sep 18, 2020

Before

node bin/benchmark-tests.js
Running 'Serialization/Write JavaScript number directly' ...
done 123.83756804466248 ms
Running 'Serialization/Write JavaScript string directly' ...
done 129.04579210281372 ms
Running 'Serialization/Swift Int to JavaScript' ...
done 3677.7331490516663 ms
Running 'Serialization/Swift String to JavaScript' ...
done 5490.698668003082 ms
Running 'Object heap/Increment and decrement RC' ...
done 3000.8530011177063 ms

After

node bin/benchmark-tests.js
Running 'Serialization/Write JavaScript number directly' ...
done 130.88212418556213 ms
Running 'Serialization/Write JavaScript string directly' ...
done 137.1980230808258 ms
Running 'Serialization/Swift Int to JavaScript' ...
done 3526.049220085144 ms
Running 'Serialization/Swift String to JavaScript' ...
done 3598.435418844223 ms
Running 'Object heap/Increment and decrement RC' ...
done 2782.3261749744415 ms

/// - lhs: A string to compare.
/// - rhs: Another string to compare.
public static func == (lhs: JSString, rhs: JSString) -> Bool {
return lhs.guts.buffer == rhs.guts.buffer
Copy link
Contributor

Choose a reason for hiding this comment

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

Could there be a way to run this comparison on the JS side, without potentially triggering copies?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a trade-off point. If we compare them in JS side, it may trigger copies and re-encode Swift string to JS

Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to add a flag to Guts that reports whether the value is cached in Swift? That way it would be possible to do the check in JS if neither string is cached in Swift.

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Great stuff! 👏

@kateinoigakukun kateinoigakukun merged commit 36a06c5 into master Sep 18, 2020
@kateinoigakukun kateinoigakukun deleted the js-string branch September 18, 2020 11:06
}()

lazy var buffer: String = {
var bytesRef: JavaScriptObjectRef = 0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var bytesRef: JavaScriptObjectRef = 0
var bytesRef = JavaScriptObjectRef()

/// - lhs: A string to compare.
/// - rhs: Another string to compare.
public static func == (lhs: JSString, rhs: JSString) -> Bool {
return lhs.guts.buffer == rhs.guts.buffer
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to add a flag to Guts that reports whether the value is cached in Swift? That way it would be possible to do the check in JS if neither string is cached in Swift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants