Skip to content

Instantly share code, notes, and snippets.

@vlsi
vlsi / 00_conclusions.md
Last active April 16, 2024 21:10
The fastest way of string concatenation in Oracle PL/SQL

When builing large strings with lots of concatenations in PL/SQL, custom approach like "use varchar2(32000) buffer to reduce the number of dbms_lob calls" makes sense even for Oracle 12.1.0.2.0.

The response time improvement is 4..300+ times :) depending on the DB version and API you use.

Note that simple v_clob || TO_CHAR (SYSTIMESTAMP) || ', ' ==> v_clob || TO_CLOB(TO_CHAR (SYSTIMESTAMP) || ', ') trick (note the extra to_clob) makes 24 times improvement for 11g. The trick is bad for 12c where results in 1.5x degradation.

The code was published 4 year ago as an answer to "How to Quickly Append VARCHAR2 to CLOB": http://www.talkapex.com/2009/06/how-to-quickly-append-varchar2-to-clob.html?showComment=1343235921606#c9077980873875311325

@vlsi
vlsi / results.md
Last active December 16, 2023 15:45
Benchmark results for JDK-8321271 Add OutputStream.write(ByteBuffer)
@vlsi
vlsi / 01_plan_flipper.sql
Last active May 22, 2023 13:34
PostgreSQL plan flipper
-- This sample reproduces a bug of a "sudden" flip of a server-prepared statement in PG 9.2+
-- In this particular case, backend selects very bad index even though bind values are the same and the table is analyzed
TL;DR: if you want to know true execution plan for a query with bind variables, you must use "prepare...";
then repeat "explain analyze execute" 6 times :)
-- Note: do not confuse "5 executions before pgjdbc starts to use server-prepared statements" with
-- "first 5 executions of a server-prepared statement before plan flip"
-- Here's discussion in pgsql-hackers list:
@vlsi
vlsi / kotlin_vs_java_generic_variance.md
Last active November 3, 2022 08:35
I would definitely recommend Kotlin generics to a Java fellow, here's why

Generics in Java are hard (sad, but true), however, Kotlin makes them way more accessible 🤩.

Suppose you are doing property-based testing. Just like I suggest, I was creating a jqwik test, and I ran into an issue with generic signatures.

Here's a minimal example, and it already has two issues.

Take a second and find both of them 😉

@vlsi
vlsi / HotspotAllocationProfilerTest output
Created April 12, 2015 13:44
HotspotAllocationProfilerTest output
# Run complete. Total time: 00:00:05
Benchmark Mode Cnt Score Error Units
HotspotAllocationProfilerTest.allocateObject avgt 4,297 ns/op
HotspotAllocationProfilerTest.allocateObject:·allocated avgt 16,002 B/op
HotspotAllocationProfilerTest.allocateObject:·allocation.rate avgt 3202,343 MB/sec
HotspotAllocationProfilerTest.allocateObjectSampleTime sample 15583 56,291 ± 3,064 ns/op
HotspotAllocationProfilerTest.allocateObjectSampleTime:·allocated sample 16,001 B/op
HotspotAllocationProfilerTest.allocateObjectSampleTime:·allocation.rate sample 1941,053 MB/sec
HotspotAllocationProfilerTest.allocateObjectSingleShot ss 5 1287,800 ± 302,336 ns/op
@vlsi
vlsi / ConcurrentHashMapKotlin.kt
Created May 10, 2021 13:10
A translation of OpenJDK's ConcurrentHashMap to Kotlin
import java.util.concurrent.ThreadLocalRandom
/**
* This is mostly automatic Java to Kotlin conversion followed with cleanups.
* See https://twitter.com/tagir_valeev/status/1391615535889137665
*/
object ConcurrentHashMapKotlin {
class TreeNode<K, V> {
// red-black tree links
var parent: TreeNode<K, V>? = null
@vlsi
vlsi / peg-parser.txt
Created April 17, 2021 13:17
SpringDataПостроительПарсер
// See https://pegjs.org/online
// Sample expressions:
// FindBy${Name}
// FindFirstBy${Name}
// FindBy${Name}And${OperationType}OrderBy${Name}And${OperationType}DescCount
Query "query"
= s:Start t:Transform* f:Finalizer?
{ return {start: s, transforms: t, finalizer: f} }
@vlsi
vlsi / build.gradle.kts
Last active October 7, 2020 12:14
Add Class-Path attribute to a jar manifest in Gradle
// Add Class-Path to the existing "jar" task
tasks.jar {
val classpath = configurations.runtimeClasspath
// Input declaration is needed for the proper up-to-date checks
inputs.files(classpath).withNormalizer(ClasspathNormalizer::class.java)
manifest {
attributes(
"Class-Path" to classpath.map { cp -> cp.joinToString(" ") { it.absolutePath } }
)
}
@vlsi
vlsi / publish-to-custom-nexus-repository.md
Last active April 28, 2020 18:31
Publishing Gradle-based Java artifacts to a custom Nexus repository

Apache Maven enables developers to augment repository URL via settings.xml. That might sound powerful, however, it requires to use the same repository IDs across all the projects which might not be always possible.

Let's see how Gradle-based project can be published to a custom repository.

For instance, let's try to publish Apache Calcite to our own Nexus instance. Of course we don't want to commit the URL and password of our secretNexus to GitHub, so we need to augment the build without touching the files.

Gradle has Initialization Scripts that enable users to augment all the builds without touching project-specific files.

@vlsi
vlsi / keybase.md
Created September 9, 2019 12:38
keybase.md

Keybase proof

I hereby claim:

  • I am vlsi on github.
  • I am vlsi (https://keybase.io/vlsi) on keybase.
  • I have a public key ASC2sRZGT4IKWFFWjBEznXZ8DHXjdgWnotEDW-x6_eLlYAo

To claim this, I am signing this object: