puggy
JCHJava Community | Help. Code. Learn.
•Created by Kale Vivi on 12/16/2024 in #java-help
Sequence allocation size question
Hey @Kale Vivi ,
Could you please share time expectations and what is the execution time right now?
56 replies
JCHJava Community | Help. Code. Learn.
•Created by Kale Vivi on 12/16/2024 in #java-help
Sequence allocation size question
Great! 🫶
56 replies
JCHJava Community | Help. Code. Learn.
•Created by Kale Vivi on 12/16/2024 in #java-help
Sequence allocation size question
Thank you for sharing more code.
Suggestion
56 replies
JCHJava Community | Help. Code. Learn.
•Created by Kale Vivi on 12/16/2024 in #java-help
Sequence allocation size question
So you can move repos with
saveAll
outside of for loop, and use my suggestion for it.
For other repos you can continue use your for 🙂56 replies
JCHJava Community | Help. Code. Learn.
•Created by Eukon05 on 12/16/2024 in #java-help
Modular Spring app can't find persistence provider
13 replies
JCHJava Community | Help. Code. Learn.
•Created by Kale Vivi on 12/16/2024 in #java-help
Sequence allocation size question
let me know if this helped to speedup processing the way you need it
56 replies
JCHJava Community | Help. Code. Learn.
•Created by Kale Vivi on 12/16/2024 in #java-help
Sequence allocation size question
3. With this code I suggest to use
saveAll
instead of single save
From
To
56 replies
JCHJava Community | Help. Code. Learn.
•Created by Kale Vivi on 12/16/2024 in #java-help
Sequence allocation size question
OK, I see.
What i can suggest you here
1. instead of checking
existsBy
one by one. DO it for batch of ids you already have from splitted array
It will reduce DB interaction from N calls to M calls where N - number of persons, M - number of lists (after splitting)
2. Improve exists/not exists logic with splitting into 2 arrays from the result you would have after point 1.
56 replies
JCHJava Community | Help. Code. Learn.
•Created by Eukon05 on 12/16/2024 in #java-help
Modular Spring app can't find persistence provider
Hey @Eukon05,
Could you post stacktrace for better understanding the issue?
Thanks.
13 replies
JCHJava Community | Help. Code. Learn.
•Created by Kale Vivi on 12/16/2024 in #java-help
Sequence allocation size question
Use java streams instead. You can use
parallelStream
there and it will boost a lot the processing56 replies
JCHJava Community | Help. Code. Learn.
•Created by halofixer on 12/16/2024 in #java-help
Kotlin Branch Test coverage question
nope, i just compiled this code after @halofixer highlighted that it was null safe check
15 replies
JCHJava Community | Help. Code. Learn.
•Created by halofixer on 12/16/2024 in #java-help
Kotlin Branch Test coverage question
Ah, I see it now — you’re using the null-safe operator
(?.)
only after house
. My mistake here.
From what I know about how Kotlin generates bytecode, it should be the next 8 branches:
Each ?. operator (like the one after house) introduces 2 branches:
1. One for when the value is null (short-circuits the rest of the chain).
2. One for when the value is not null (proceeds to the next step).
The contains("Steve") method call introduces 2 branches:
1. One for when it returns true.
2. One for when it returns false.
The == true comparison adds another 2 branches:
1. One for when the result matches true.
2. One for when it does not match true.
That’s how you end up with 8 branches
: 2 (for ?.)
× 2 (for contains)
× 2 (for == true)
.
I missed this earlier because I was thinking about the null-safety starting at the very beginning of the chain :<
Does it make sense now for you?
4 branches are a high-level conceptual view, but a great catch here15 replies
JCHJava Community | Help. Code. Learn.
•Created by halofixer on 12/16/2024 in #java-help
Kotlin Branch Test coverage question
Hi @halofixer ,
The reason you're seeing 8 branches instead of 4 is due to how the compiler breaks down your null-safe calls (?.) and logical operations when generating bytecode. Each null check (neighborhood, street, house, family) and the method call (contains) is treated as a separate conditional path. Here's the breakdown:
1. neighborhood is null.
2. neighborhood.street is null.
3. neighborhood.street.house is null.
4. neighborhood.street.house.family is null.
5. family.contains("Steve") returns false.
6. family.contains("Steve") returns true.
7. The == true comparison for true.
8. The == true comparison for false.
To confirm, you can decompile the bytecode using
javap -c
and see how the branches are split. To achieve 100% test coverage, you'll need test cases covering all these possibilities, including combinations of null values and different results for contains.15 replies
JCHJava Community | Help. Code. Learn.
•Created by Kale Vivi on 12/16/2024 in #java-help
Sequence allocation size question
Hi @Kale Vivi ,
If you're batch inserting 50,000 records in chunks of 500 and you're using a sequence generator with allocationSize set to 1, that’s almost certainly the root cause of your performance issues. Setting allocationSize to 1 forces the database to fetch a new sequence value for every single record, which is incredibly inefficient for batch operations.
You should align your allocationSize with your batch size. In this case, setting allocationSize to 500 will allow the sequence generator to allocate 500 IDs in a single call. This drastically reduces the number of round trips to the database for sequence generation. Here’s how it works:
- When allocationSize is 500, the sequence generator pre-fetches 500 values in one call and assigns them to your records as needed.
- For a batch of 500 inserts, this means the database only hits the sequence once per batch, instead of 500 times.
56 replies