Skip to content

perf: decrease mem cost#757

Merged
fatelei merged 1 commit into
langgenius:mainfrom
fatelei:mem
Jun 8, 2026
Merged

perf: decrease mem cost#757
fatelei merged 1 commit into
langgenius:mainfrom
fatelei:mem

Conversation

@fatelei
Copy link
Copy Markdown
Contributor

@fatelei fatelei commented Jun 8, 2026

Description

fix #756

previously, ModelProperties was converted inside every MarshalJSON call:

result := mapping.ConvertAnyMap(m.ModelProperties)
m.ModelProperties = result

However, because MarshalJSON was defined on a value receiver, m is a copy, so the converted result is never written back to the original object. The next serialization still repeats the conversion from scratch.
Now this is done early, after deserialization/loading, using a pointer receiver:

m.ModelProperties = result

The original object is normalized in place, so subsequent MarshalJSON calls serialize the already-converted map[string]any directly without repeating the recursive conversion.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • Other

Essential Checklist

Testing

  • I have tested the changes locally and confirmed they work as expected
  • I have added unit tests where necessary and they pass successfully

Bug Fix (if applicable)

  • I have used GitHub syntax to close the related issue (e.g., Fixes #123 or Closes #123)

Additional Information

Please provide any additional context that would help reviewers understand the changes.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. go Pull requests that update go code labels Jun 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors session message serialization by introducing a structured pluginInStreamMessage type and using standard json.Marshal instead of a custom parser. It also moves the normalization of model properties from serialization (MarshalJSON) to deserialization (UnmarshalJSON/UnmarshalYAML) and cache retrieval steps, accompanied by new unit tests. The review feedback highlights a potential issue in Session.Message where the error from json.Marshal is ignored, which could lead to silent failures or panics if serialization fails, and suggests logging this error.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread internal/core/session_manager/session.go
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 8, 2026
@fatelei fatelei merged commit 0e9c3cf into langgenius:main Jun 8, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: reduce excessive allocations caused by repeated JSON normalization

2 participants