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

Optimise "buffer adjust" command #134

Open
stevesims opened this issue Jan 14, 2024 · 1 comment
Open

Optimise "buffer adjust" command #134

stevesims opened this issue Jan 14, 2024 · 1 comment

Comments

@stevesims
Copy link
Contributor

the buffer adjust command is arguably rather slow, and the command would be more useful if it were optimised

probably the biggest performance inhibitor is the current "byte by byte" approach, which iterates thru data and has a "switch" statement within that to deal with the operation being performed. flipping that on its head so that the "switch" is removed could potentially lead to performance improvements

@TurboVega
Copy link
Contributor

The idea of flipping the loop on its head is a good one, because the general rule of "do something once, rather than multiple times in a loop" applies. However, that fix is insufficient, because the get_byte() function constantly traverses the list of buffers in order to obtain a single byte of data, meaning that it does that same operation (finding the right buffer) in a loop, rather than once. Thus, get_byte() does not follow the above rule.

I would suggest either of two approaches:

(1) Move the adjustment operation down to the block level, and call it from the adjust() function, indicating the number of consecutive bytes (within that block) to adjust. This implies either passing the operation, and having a switch statement at the block level (outside any loop), or having a separate function for each operation at the block level (with a loop in each function).

(2) Provide a function (if not already) that gets a pointer to the data in a block, and a function (if not already) that gets the size of the block. In the adjust() loop, get those two values (block and size), and use those in a specific loop (in the adjust() function) to that ONE operation on consecutive bytes.

Either approach implies having a separate loop for each operation, so that there is no test (switch or comparison) of the type of operation, inside the byte loop. In the adjust() function, there will still be a loop, but it should go through blocks, not bytes.

Hope that makes sense.

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