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

[optimization] buffer can be dynamically allocated after calculation of required size #3

Open
XakerTwo opened this issue Oct 23, 2024 · 2 comments

Comments

@XakerTwo
Copy link
Contributor

main buffer defined as char buffer[1024*1024];
and the only place it accessed is append_to_buffer() - generate-cat-file.c @ 109
however, inside the buffer is accessed only on write pass, else - just check of its size not exceeded
but why? you can achieve more dynamic behaviour in term of buffer size by these few actions

in addition you can add size limitation just before allocation.

also you can optimize encode_sequence() (or all similar functions) to something like

//this code is from previous iteration of my version, based on your
size_t encode_sequence(void *s, size_t a_fn(void*, bool), bool write)
{
	size_t len = a_fn(s, false);

	size_t l2 = encode_tag_and_length(SEQUENCE_TAG, len, write);
	if (write)
		return a_fn(s, write) + l2;

	return len + l2;
}

so encode_sequence(p, f, false) will be faster and cheaper, cuz there will be no useless run on write=false, that anyway would have been checked inside append_to_buffer()
ideally no function should reach append_to_buffer() on write=false

@johannesthoma
Copy link
Collaborator

Hi this sounds very interesting. Having a fixed size buffer is probably a bad
idea because one could specify 1000+ files to encode. Are you already working
on a patch? I think it shouldn't be that hard to implement but on the other hand
it is also not that urgent (have to drop now).

@XakerTwo
Copy link
Contributor Author

XakerTwo commented Nov 7, 2024

not exactly... i altered you work in sligtly different direction, but partially this optimization implemented. Described part should be easy and done soon, but no any ETA, i assume that i'll create a PR when it's done

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