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

Reduce argument allocations for checkArgument to reduce gc pressure. #104

Merged
merged 11 commits into from
Oct 16, 2024
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
java-version: 17
cache: gradle
- name: gradle assemble
run: gradle assemble compileTestJava compileIntegrationTestJava -x test -Psignatory.keyId=38F6C7215DD49C32 -Psigning.gnupg.keyName=38F6C7215DD49C32 -Psigning.gnupg.executable=gpg
run: gradle assemble compileTestJava compileIntegrationTestJava -x test -Psignatory.keyId=90010D4396A46BAF -Psigning.gnupg.keyName=90010D4396A46BAF -Psigning.gnupg.executable=gpg
env:
ENABLE_SIGNING: true
- name: Upload source distrib
Expand Down Expand Up @@ -174,6 +174,8 @@ jobs:
path: "**/*.class"
key: ${{ runner.os }}-build-${{ github.sha }}
- name: gradle evm:referenceTest
env:
GRADLE_OPTS: "-Xmx4096m"
run: gradle evm:referenceTest
- name: Archive Junit Report
if: always()
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Licensed to the Consensys Software Inc 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.

# This is adapted from https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-gradle

name: Publish package to GitHub Packages
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
container:
image: tmio/tuweni-build:1.2
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Publish package
run: ./gradlew publishAllPublicationsToGitHubPackagesRepository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 17 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ allprojects {
publishing {
repositories {
maven {
name = "OSSRH"
def isRelease = buildVersion.endsWith('SNAPSHOT')
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
Expand Down Expand Up @@ -355,14 +356,23 @@ allprojects {
}
}
}

maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/consensys/tuweni"
credentials {
username = System.getenv('GITHUB_ACTOR')
password = System.getenv('GITHUB_TOKEN')
}
}
}
publications {
MavenDeployment(MavenPublication) { publication ->
if (project != rootProject) {
from components.java
artifact sourcesJar { classifier 'sources' }
}
groupId 'io.tmio'
groupId 'io.consensys.protocols'
artifactId 'tuweni-' + project.name
version project.version

Expand All @@ -378,17 +388,17 @@ allprojects {
pom {
name = project.name
afterEvaluate { description = project.description }
url = 'https://github.com/tmio/tuweni'
url = 'https://github.com/consensys/tuweni'
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
scm {
connection = 'scm:https://github.com/tmio/tuweni.git'
developerConnection = 'scm:git@github.com:tmio/tuweni.git'
url = 'https://github.com/tmio/tuweni'
connection = 'scm:https://github.com/consensys/tuweni.git'
developerConnection = 'scm:git@github.com:consensys/tuweni.git'
url = 'https://github.com/consensys/tuweni'
}
developers {
developer {
Expand All @@ -400,7 +410,7 @@ allprojects {
}
issueManagement {
system = "github"
url = "https://www.github.com/tmio/tuweni/issues"
url = "https://www.github.com/consensys/tuweni/issues"
}
}

Expand All @@ -415,7 +425,7 @@ allprojects {
def addDependencyNode = { dep, optional, scope ->
def dependencyNode = dependenciesNode.appendNode('dependency')
if (dep instanceof ProjectDependency) {
dependencyNode.appendNode('groupId', 'io.tmio')
dependencyNode.appendNode('groupId', 'io.consensys')
dependencyNode.appendNode('artifactId', rootProject.name + '-' + dep.name)
dependencyNode.appendNode('version', dep.version)
} else {
Expand Down
43 changes: 43 additions & 0 deletions bytes/src/main/java/org/apache/tuweni/bytes/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,47 @@ static void checkArgument(boolean condition, String message, Object... args) {
throw new IllegalArgumentException(String.format(message, args));
}
}

@FormatMethod
static void checkArgument(boolean condition, String message) {
if (!condition) {
throw new IllegalArgumentException(message);
}
}

@FormatMethod
static void checkArgument(boolean condition, String message, int arg1) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1));
}
}

@FormatMethod
static void checkArgument(boolean condition, String message, int arg1, int arg2) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1, arg2));
}
}

@FormatMethod
static void checkArgument(boolean condition, String message, int arg1, int arg2, int arg3) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1, arg2, arg3));
}
}

@FormatMethod
static void checkArgument(
boolean condition, String message, int arg1, int arg2, int arg3, int arg4) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1, arg2, arg3, arg4));
}
}

@FormatMethod
static void checkArgument(boolean condition, String message, long arg1) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.tuweni.discovery
*/

import io.vertx.core.Vertx
import io.vertx.core.VertxException
import io.vertx.core.dns.DnsClient
import io.vertx.core.dns.DnsClientOptions
import io.vertx.core.dns.DnsException
Expand All @@ -31,6 +32,7 @@ import org.apache.tuweni.crypto.SECP256K1
import org.apache.tuweni.devp2p.EthereumNodeRecord
import org.slf4j.LoggerFactory
import java.io.IOException
import java.lang.Exception

/**
* Resolves a set of ENR nodes from a host name.
Expand Down Expand Up @@ -153,11 +155,18 @@ class DNSResolver @JvmOverloads constructor(
return null
}
} catch (e: DnsException) {
logger.warn("DNS query error with $domainName", e)
logger.debug("DNS query error with $domainName", e)
return null
} catch (e: IOException) {
logger.warn("I/O exception contacting remote DNS server when resolving $domainName", e)
return null
} catch (e: VertxException) {
// timeouts are common
logger.warn("Vertx exception contacting remote DNS server when resolving $domainName", e)
return null
} catch (e: Exception) {
logger.warn("Exception contacting remote DNS server when resolving $domainName", e)
return null
}
}

Expand Down
Loading
Loading