Skip to content

Use StandardCharsets.UTF_8 in JacksonSerializer#49

Merged
jaredmixpanel merged 2 commits intofeature/jackson-performance-optimizationfrom
copilot/sub-pr-48
Nov 21, 2025
Merged

Use StandardCharsets.UTF_8 in JacksonSerializer#49
jaredmixpanel merged 2 commits intofeature/jackson-performance-optimizationfrom
copilot/sub-pr-48

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 21, 2025

Replaces string literal "UTF-8" with StandardCharsets.UTF_8 in JacksonSerializer.serializeArrayToBytes() to eliminate unnecessary checked exception handling and improve type safety.

Changes:

  • Added java.nio.charset.StandardCharsets import
  • Changed "[]".getBytes("UTF-8") to "[]".getBytes(StandardCharsets.UTF_8) on line 46

This aligns JacksonSerializer with the existing pattern in OrgJsonSerializer (line 32).


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix optional Jackson serialization for performance improvement Use StandardCharsets.UTF_8 in JacksonSerializer Nov 21, 2025
Copilot AI requested a review from jaredmixpanel November 21, 2025 21:36
@jaredmixpanel jaredmixpanel marked this pull request as ready for review November 21, 2025 21:43
@jaredmixpanel jaredmixpanel merged commit 6db4103 into feature/jackson-performance-optimization Nov 21, 2025
jaredmixpanel added a commit that referenced this pull request Nov 24, 2025
…n large batches (#48)

* feat: Add optional Jackson serialization for 5x performance improvement

Implements high-performance JSON serialization using Jackson's streaming API
while maintaining complete backward compatibility with the existing org.json
public API.

Key improvements:
- Automatic detection and use of Jackson when available on classpath
- Up to 5x performance improvement for large batch imports (50+ messages)
- Zero breaking changes - all public APIs remain unchanged
- Graceful fallback to org.json when Jackson is not available

Performance benchmarks show:
- Small batches (1-10 messages): 1.2-1.5x faster
- Medium batches (50-100 messages): ~5x faster
- Large batches (500-2000 messages): ~5x faster consistently

Implementation details:
- Created internal JsonSerializer interface for pluggable implementations
- JacksonSerializer uses streaming API to avoid conversion overhead
- SerializerFactory automatically selects best available implementation
- Modified dataString() method to use the new serialization layer

This is particularly beneficial for the /import endpoint which handles
up to 2000 messages per batch (40x larger than regular /track endpoint).

Users simply add jackson-databind dependency to enable this optimization.
No code changes required - the library automatically detects and uses it.

* Add exception logging to Jackson serialization fallback (#50)

* Initial plan

* Add logging for Jackson serialization fallback

Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>

* Use StandardCharsets.UTF_8 in JacksonSerializer (#49)

* Initial plan

* Use StandardCharsets.UTF_8 instead of "UTF-8" string literal

Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>

* Update src/test/java/com/mixpanel/mixpanelapi/internal/SerializerBenchmark.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* chore: Update Jackson version to 2.20.0

Updates Jackson dependency from 2.15.3 to 2.20.0 for the latest
performance improvements and security patches.

* Update src/main/java/com/mixpanel/mixpanelapi/MixpanelAPI.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jaredmixpanel <10504508+jaredmixpanel@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants