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

Deprecate for WeakRefString's InlineString #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

oxinabox
Copy link
Member

I don't care to duplicate efforts.
InlineStrings is just a more complete implementation of this idea.
With a few extra clever tricks.

cc @quinnj

README.md Outdated Show resolved Hide resolved
@ScottPJones
Copy link
Member

I think that deprecating ShortStrings should wait, InlineString doesn't completely replace SSs (it doesn't have a string macro to make using them more convenient, for example), and it really needs some performance testing done, to see how it compares to other string types, such as String and ShortString. (I've already seen a few cases where it is substantially slower - in one simple case, 273x slower!)

@quinnj
Copy link

quinnj commented Sep 30, 2021

Please share the performance checking you've done; I tested every function defined in the InlineStrings.jl package and it was faster or on par with everything in ShortStrings. I'll find a link to the perf testing I did, but it was pretty substantial.

@ScottPJones
Copy link
Member

I just did some simple tests of ==, comparing different sized InlineStrings to each other, to Strings, and SubStrings.
In many places, it looks like operations fall back to ones in Base - in others, what may be an issue is that I believe that when a Ref{T} is created (so that you can get a pointer and then call memcmp), that has to allocate (where?) some memory and then store the InlineString there.

@quinnj
Copy link

quinnj commented Oct 2, 2021

julia> x = InlineString("hey")
"hey"

julia> y = "hey"
"hey"

julia> typeof(x)
String3

julia> typeof(y)
String

julia> @btime x == y
  15.004 ns (0 allocations: 0 bytes)
true

julia> @btime y == y
  12.275 ns (0 allocations: 0 bytes)
true

julia> @btime x == x
  11.479 ns (0 allocations: 0 bytes)
true

julia> z = ShortString("hey")
"hey"

julia> typeof(z)
ShortString3 (alias for ShortString{UInt32})

julia> @btime y == z
  15.442 ns (0 allocations: 0 bytes)
true

julia> @btime y == y
  11.114 ns (0 allocations: 0 bytes)
true

julia> x = InlineString("a"^255)
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

julia> y = "a"^255
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

julia> z = ShortString("a"^255)
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

julia> @btime x == y
  34.052 ns (0 allocations: 0 bytes)
true

julia> @btime z == y
  925.439 ns (0 allocations: 0 bytes)
true

sampling other sizes of InlineStrings/ShortStrings seems to show similar results; it seems like ShortStrings gets significantly slower for some reason for the 128/255 byte cases; otherwise, the performance seems about equal for all other sizes.

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