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

Fix #1775: use optimized CqlVector<Float> codec to improve performance #1801

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

tatu-at-datastax
Copy link
Contributor

@tatu-at-datastax tatu-at-datastax commented Dec 18, 2024

What this PR does:

Will use optimized CQL driver codec for Vector<Float> to reduce extra memory allocations, improve performance of reading and writing CQL Float vectors (problem found by profiling).

NOTE: optimized codec is from here:

https://github.com/absurdfarce/cassandra-java-driver/tree/subtype-only-vector-codec

Which issue(s) this PR fixes:
Fixes #1775

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

@tatu-at-datastax
Copy link
Contributor Author

So far so good: return direction (Vector results from driver) now works.

@tatu-at-datastax tatu-at-datastax changed the title (WIP) Fix #1775: use optimized CqlVector<Float> codec to improve performance Fix #1775: use optimized CqlVector<Float> codec to improve performance Dec 19, 2024
@tatu-at-datastax tatu-at-datastax marked this pull request as ready for review December 19, 2024 00:08
@tatu-at-datastax tatu-at-datastax requested a review from a team as a code owner December 19, 2024 00:08
Iterator<String> strIterator = strIterable.iterator();
for (int i = 0; i < rv.length; ++i) {
String strVal = strIterator.next();
// TODO: String.isBlank() should be included here but it's only available with Java11+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are using Java 21, why don't we use String.isBlank() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code was first written for Java CQL driver (by Brett). I can change that, thanks.

Comment on lines +1 to +17
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly just copied over, we don't. Can remove.

public class SubtypeOnlyFloatVectorTest {

@Test
public void should_find_subtype_only_codec_regardless_of_size() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why do we use the snake case but not the camel case? Is it because the name is too long?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as earlier, something Java driver probably does (I copied over as-is).

Not something we should do.

Comment on lines +1 to +17
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as the above

}

@Test
public void should_encode() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are all the methods in this class using snake case?

Comment on lines +106 to +107
throw new IllegalArgumentException(
String.format("Input ByteBuffer should have a multiple of %d bytes", ELEMENT_SIZE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how common this exception is. If this is a common error, should we use Error V2 instead of IllegalArgumentException? Have the same question for other IllegalArgumentExceptions. Or all these IllegalArgumentExceptions will be caught eventually and converted to our own errors? I see there is caught in VectorCodec and convert it to ToCQLCodecException, but not sure if it covers all the cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This codec is used by Java CQL Driver, it's not a Data API codec. But I think code we use for java driver will have to catch exceptions anyway. Problem itself should not be possible to occur by any external calls; it is more an assertion (and as such not sure there is a way to easily test).

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

Successfully merging this pull request may close these issues.

Perf improvement: make CQL driver use optimized CqlVector<Float> codec to improve performance
2 participants