Skip to content

Commit

Permalink
Micro optimization to avoid inline creation & spreading of objects / …
Browse files Browse the repository at this point in the history
…arrays (#1847)
  • Loading branch information
fubhy authored Jan 1, 2024
1 parent 693b8f3 commit bcf0900
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/neat-geese-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@effect/opentelemetry": patch
"@effect/platform": patch
"effect": patch
---

Avoid inline creation & spreading of objects and arrays
12 changes: 7 additions & 5 deletions packages/effect/src/internal/core-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2033,11 +2033,13 @@ export const makeSpan = (
: Context.getOption(context, internalTracer.spanTag)

const links = linksFromEnv._tag === "Some" ?
[
...Chunk.toReadonlyArray(linksFromEnv.value),
...(options?.links ?? [])
] :
options?.links ?? []
options?.links !== undefined ?
[
...Chunk.toReadonlyArray(linksFromEnv.value),
...options?.links ?? []
] :
Chunk.toReadonlyArray(linksFromEnv.value) :
options?.links ?? ReadonlyArray.empty()

const span = tracer.span(
name,
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry/src/NodeSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const layerTracerProvider = (
Effect.acquireRelease(
Effect.sync(() => {
const provider = new NodeTracerProvider({
...(config ?? {}),
...(config ?? undefined),
resource
})
provider.addSpanProcessor(processor)
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry/src/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const layer = (config: {
readonly attributes?: Resources.ResourceAttributes
}) => {
const attributes = {
...(config.attributes ?? {}),
...(config.attributes ?? undefined),
[SemanticResourceAttributes.SERVICE_NAME]: config.serviceName,
[SemanticResourceAttributes.TELEMETRY_SDK_NAME]: "@effect/opentelemetry",
[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]: typeof (globalThis as any).document === "undefined"
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry/src/WebSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const layerTracerProvider = (
Effect.acquireRelease(
Effect.sync(() => {
const provider = new WebTracerProvider({
...(config ?? {}),
...(config ?? undefined),
resource
})
provider.addSpanProcessor(processor)
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/src/internal/http/clientRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const make: {
modify(empty, {
method,
url,
...(options ?? {})
...(options ?? undefined)
})

/** @internal */
Expand Down

0 comments on commit bcf0900

Please sign in to comment.