optimizely / optimizely/javascript-sdk
[BUG] Memory leak when migrating from v5 to v6
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 82
- Fork
- 86
- Merge trung bình
- 2 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 3
Mô tả
Is there an existing issue for this?
- I have searched the existing issues
SDK Version
6.3.1
Current Behavior
Memory increases over time and is not garbage collected
Expected Behavior
Memory is like it was before
Steps To Reproduce
We rewrote the optimizely instance creation from:
const DEFAULT_DATAFILE_OPTIONS = {
autoUpdate: true,
updateInterval: 5 * 60 * 1000 // 5 minutes
}
const DEFAULT_EVENTS_OPTIONS = {
batchSize: 10,
flushInterval: 1000
}
const DEFAULT_TIMEOUT = 500
const LOGGER_LEVEL = process.env.NODE_ENV === 'production' ? ERROR : INFO
export default class OptimizelyAdapter {
static createOptimizelyInstance({
options: optionParameter,
sdkKey,
datafile,
optimizely = optimizelySDK,
eventDispatcher = optimizelySDK.eventDispatcher
}) {
const options = {...DEFAULT_DATAFILE_OPTIONS, ...optionParameter}
optimizely.setLogLevel(LOGGER_LEVEL)
optimizely.setLogger(optimizely.logging.createLogger())
if (!datafile && typeof window !== 'undefined' && window.__INITIAL_CONTEXT_VALUE__?.pde) {
datafile = window.__INITIAL_CONTEXT_VALUE__.pde
sdkKey = undefined
}
const isServer = typeof window === 'undefined'
const optimizelyInstance = optimizely.createInstance({
sdkKey,
datafileOptions: options,
datafile,
eventDispatcher,
...DEFAULT_EVENTS_OPTIONS,
defaultDecideOptions: isServer ? [optimizely.OptimizelyDecideOption.DISABLE_DECISION_EVENT] : []
})
return optimizelyInstance
}
}
To:
const DEFAULT_DATAFILE_OPTIONS = {
autoUpdate: true,
updateInterval: 5 * 60 * 1000 // 5 minutes
}
const DEFAULT_EVENTS_OPTIONS = {
batchSize: 10,
flushInterval: 1000
}
const DEFAULT_TIMEOUT = 500
const LOGGER_LEVEL = process.env.NODE_ENV === 'production' ? ERROR : INFO
export default class OptimizelyAdapter {
static createOptimizelyInstance({options: optionParameter, sdkKey, datafile}) {
if (!datafile && typeof window !== 'undefined' && window.__INITIAL_CONTEXT_VALUE__?.pde) {
datafile = window.__INITIAL_CONTEXT_VALUE__.pde
sdkKey = undefined
}
const isServer = typeof window === 'undefined'
const projectConfigManager = sdkKey
? createPollingProjectConfigManager({sdkKey, datafile, ...DEFAULT_DATAFILE_OPTIONS, ...optionParameter})
: createStaticProjectConfigManager({datafile})
const eventProcessor = createBatchEventProcessor({
...DEFAULT_EVENTS_OPTIONS,
...optionParameter
})
const odpManager = createOdpManager()
const logger = createLogger({
level: LOGGER_LEVEL
})
return createInstance({
projectConfigManager,
eventProcessor,
odpManager,
logger,
defaultDecideOptions: isServer ? [OptimizelyDecideOption.DISABLE_DECISION_EVENT] : []
})
}
}
The instance is created in the server during bootstrap and we just create one. We would like to keep the current behaviour as it is (not using the disposable flag). I will try to do some memory snapshots but I was wondering is something is wrong since we only changed this part following your migration from v5 to v6 guide
SDK Type
Browser
Node Version
JS SDK
Browsers impacted
No response
Link
No response
Logs
No response
Severity
No response
Workaround/Solution
No response
Recent Change
No response
Conflicts
No response
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với thay đổi tạo instance từ v5 sang v6 được nêu trong issue và tái hiện trường hợp server-bootstrap tạo một instance. So sánh các snapshot bộ nhớ theo thời gian, tập trung vào trình quản lý cấu hình project, event processor, ODP manager, logger và đường dẫn createInstance. Hoàn tất có nghĩa là xác định nguồn của phần bộ nhớ bị giữ lại và xác nhận hành vi bộ nhớ ổn định mà không bật disposable flag.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- backend, performance
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 28/100