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

Perfomance index #295

Open
duytungth opened this issue Apr 5, 2022 · 3 comments
Open

Perfomance index #295

duytungth opened this issue Apr 5, 2022 · 3 comments

Comments

@duytungth
Copy link

duytungth commented Apr 5, 2022

I have class:

public class Product {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	private String name, code;

	@Transient
	public static final Attribute<Product, Boolean> IS_VISIBLE = attribute(Fields.visible, Product::isVisible);
	@Transient
	public static final Attribute<Product, String> PRODUCT_NAME = attribute(Fields.name, Product::getName);
	@Transient
	public static final Attribute<Product, String> PRODUCT_CODE = attribute(Fields.code, Product::getCode);
}

Query:

and(or(contains(PRODUCT_NAME, query.getKeyword()),
            contains(PRODUCT_CODE, query.getKeyword())),
       equal(IS_VISIBLE, true)
)

First time I index like this:

        this.products = new TransactionalIndexedCollection<>(Product.class);
        this.products.addIndex(NavigableIndex.onAttribute(IS_VISIBLE));
        this.products.addIndex(SuffixTreeIndex.onAttribute(PRODUCT_NAME));
        this.products.addIndex(SuffixTreeIndex.onAttribute(PRODUCT_CODE));

Second time I index like this:

        this.products = new TransactionalIndexedCollection<>(Product.class);
        this.products.addIndex(NavigableIndex.onAttribute(IS_VISIBLE));
        this.products.addIndex(NavigableIndex.onAttribute(PRODUCT_NAME));
        this.products.addIndex(NavigableIndex.onAttribute(PRODUCT_CODE));

Why first time faster than second time about 3-5 ms? Although query use contains method?
I just spam about 10 -15 queries

@npgall
Copy link
Owner

npgall commented Apr 5, 2022

If i understand your question correctly it's because the NavigableIndex does not support contains() queries, whereas the SuffixTreeIndex does. So you should expect better performance with SuffixTreeIndex for contains() queries.

@duytungth
Copy link
Author

duytungth commented Apr 6, 2022

Oh sorry, i mean NavigableIndex have better performance with SuffixTreeIndex with above Query sentence, while SuffixTreeIndex support contains() queries

@npgall
Copy link
Owner

npgall commented Apr 6, 2022

One potential factor is how big is your dataset? Using an index can be more expensive than iteration if the dataset is small.

Another factor could be the microbenchmark setup. Could you share details of how you are running those tests? The overhead of class loading the bytecode for additional classes when you use additional indexes, and JIT compilation could be a factor as well.

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