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

ChunkWriteStream>>#nextPut: contains a very inefficient loop #5029

Closed
svenvc opened this issue Oct 29, 2019 · 4 comments
Closed

ChunkWriteStream>>#nextPut: contains a very inefficient loop #5029

svenvc opened this issue Oct 29, 2019 · 4 comments

Comments

@svenvc
Copy link
Contributor

svenvc commented Oct 29, 2019

ChunkWriteStream>>#nextPut: contains a very inefficient loop, making lots of copies while it goes forward.

Here is a better implementation, POC style:

(PharoSyntaxTutorial>>#theEnd) sourceCode in: [ :string |
	"double exclamation marks ($!) in string and add an extra one at the end"
	String streamContents: [ :out | | start bangIndex |
		start := 1.
		[ (bangIndex := string indexOf: $! startingAt: start) = 0 ] whileFalse: [ 
			out next: bangIndex - start + 1 putAll: string startingAt: start.
			out nextPut: $!.
			start := bangIndex + 1 ].
		out next: string size - start + 1 putAll: string startingAt: start.
		out nextPut: $! ]
]

This does require the addition of #next:putAll:startingAt: to SourceFile (just a delegation).

Also, the #flush might be 'too early' for larger batches

@svenvc
Copy link
Contributor Author

svenvc commented Oct 29, 2019

WriteStream>>#nextChunkPut: contains the same inefficient loop

@svenvc
Copy link
Contributor Author

svenvc commented Oct 29, 2019

#5034

@Ducasse
Copy link
Member

Ducasse commented Oct 31, 2019

Nobody ever looked at this ugly code since decades.
Thanks!
You get an impact.
I was wondering how we could collect some benchmarks.
what was the improvement?

@svenvc
Copy link
Contributor Author

svenvc commented Oct 31, 2019

I don't think it will be faster, but it will certainly generate less garbage, especially when there are $! in the source code.

But it is a bit hard to measure.

@svenvc svenvc closed this as completed Oct 31, 2019
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

No branches or pull requests

2 participants