Skip to content

Smart strings#259

Merged
sbarzowski merged 1 commit intogoogle:masterfrom
sbarzowski:smart-strings
Jan 4, 2020
Merged

Smart strings#259
sbarzowski merged 1 commit intogoogle:masterfrom
sbarzowski:smart-strings

Conversation

@sbarzowski
Copy link
Contributor

When adding long strings, don't copy them immediately. Instead
build long strings only when their contents are requested.

This allows to build a long string from parts, using a regular
operator+ in linear time. This lets users to worry much less
about using std.join etc.

If indexing the string is mixed with building it using operator+
the behavior can still be quadratic. We may want to address it in
a later change.

Depends on: #229

@sbarzowski
Copy link
Contributor Author

Example benchmark:

std.foldl(function(e, res) e + res, std.makeArray(20000, function(i) "aaaaa"), "")

This version: 0.73s user 0.13s system 131% cpu 0.652 total
Current master: 1.64s user 1.89s system 106% cpu 3.306 total
C++ version: 1.24s user 0.61s system 98% cpu 1.872 total

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 75.586% when pulling 093a766 on sbarzowski:smart-strings into 7af3b84 on google:master.

@coveralls
Copy link

coveralls commented Feb 28, 2019

Coverage Status

Coverage increased (+0.05%) to 78.075% when pulling 8407897 on sbarzowski:smart-strings into b44e63e on google:master.

@sparkprime
Copy link
Contributor

This is a good idea. We should tune it on some realistic benchmarks if possible.

I think having a native deep join that will do 2 passes over the tree will still be faster in the case of manifest functions, but obviously that is more of an expert approach.

@sbarzowski
Copy link
Contributor Author

I rebased it and changed the names of string representations to something a little bit more concrete.

@sparkprime Can we merge this?

When adding long strings, don't copy them immediately. Instead
build long strings only when their contents are requested.

This allows to build a long string from parts, using a regular
operator+ in linear time. This lets users to worry much less
about using std.join etc.

If indexing the string is mixed with building it using operator+
the behavior can still be quadratic. We may want to address it in
a later change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants