Skip to content

10% slowdown when using iterators #14659

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

Closed
jbalintbiro opened this issue Jun 4, 2014 · 2 comments
Closed

10% slowdown when using iterators #14659

jbalintbiro opened this issue Jun 4, 2014 · 2 comments
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@jbalintbiro
Copy link

    fn find(&self, key: &K) -> Option<&V> {
        let mut cur: *mut Node<K, V> = ptr::mut_null();

/*      unsafe {
            for (level, root) in self.roots.iter().enumerate().rev() {
                if cur == ptr::mut_null() {
                    let croot = *root;
                    if croot != ptr::mut_null() && (*croot).key <= *key {
                        cur = croot;
                    }
                }

                if cur != ptr::mut_null() {
                    loop {
                        let next = *(*cur).pointer(level);
                        if next != ptr::mut_null() && (*next).key <= *key {
                            cur = next;
                        } else {
                            break;
                        }
                    }
                }
            }
            if cur != ptr::mut_null() && (*cur).key == *key {
                Some(&(*cur).value)
            } else {
                None
            }
        }
*/
        unsafe {
            for level in range(0, self.roots.len()).rev() {
                if cur == ptr::mut_null() {
                    let croot = self.roots.as_slice()[level];
                    if croot != ptr::mut_null() && (*croot).key <= *key {
                        cur = croot;
                    }
                }

                if cur != ptr::mut_null() {
                    loop {
                        let next = *(*cur).pointer(level);
                        if next != ptr::mut_null() && (*next).key <= *key {
                            cur = next;
                        } else {
                            break;
                        }
                    }
                }
            }
            if cur != ptr::mut_null() && (*cur).key == *key {
                Some(&(*cur).value)
            } else {
                None
            }
        }
    }

the commented out code runs 10% slower, whole file: https://github.com/saati/skiplist-rs/blob/6ddf457bd0dd7ac02d21cd36bca966b700037034/skiplist.rs

with iterators:
test bench::bench_search_short ... bench: 102 ns/iter (+/- 8)

without iterators:
test bench::bench_search_short ... bench: 92 ns/iter (+/- 8)

@huonw
Copy link
Member

huonw commented Jun 4, 2014

This is possibly #11751.

@huonw huonw added the I-slow label Jun 4, 2014
@thestinger
Copy link
Contributor

I believe this is fixed now. Please re-open if it's still not performing as well for you.

bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
Deduplicate crates when extending crate graphs

This is quadratic in runtime per deduplication attempt, but I don't think that'll be a problem for the workload here. Don't be scared of the diff, the actual diff is +42 -22, the rest is tests and test data.
Fixes rust-lang/rust-analyzer#14476
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

3 participants