TypeScript Version: 3.4.0-dev.201xxxxx
Typescript version: 3.4.5
Search Terms:
Redux combine reducers memory crash heap allocation
Code
// es6 import statements for actions and reducers
type FormActions = SignUpFormActionTypes &
LoginFormActionTypes &
ContactUsFormActionTypes &
ForgotPasswordFormActionTypes &
ResetPasswordFormActionTypes &
CreateBusinessFormActionTypes &
BusinessDetailsFormActionTypes &
DealFormActionsTypes &
InstantDealFormActionsTypes &
JobListingFormActionTypes &
OnlineLocationFormActionTypes &
PhysicalLocationFormActionTypes;
export default combineReducers<FormsState, FormActions>({
signUpForm: SignUpFormReducer,
loginForm: LoginFormReducer,
contactUsForm: ContactUsFormReducer,
forgotPasswordForm: ForgotPasswordFormReducer,
resetPasswordForm: ResetPasswordFormReducer,
createBusinessForm: CreateBusinessFormReducer,
businessDetailsForm: BusinessDetailsFormReducer,
dealForm: DealFormReducer,
instantDealForm: InstantDealFormReducer,
jobListingForm: JobListingFormReducer,
onlineLocationForm: OnlineLocationFormReducer,
physicalLocationForm: PhysicalLocationFormReducer,
});
For example, an action type looks like this:
export type LoginFormActionTypes =
| SubmitLoginAction
| LoginSuccessAction
| LoginFailedAction;
And each of those actions are plain javascript classes that implement from Action<> in the redux library
Expected behavior:
Should run tsc without issues
Actual behavior:
npx tsc
<--- Last few GCs --->
[59352:0000023E65B36200] 42665 ms: Mark-sweep 1391.2 (1425.2) -> 1390.9 (1425.7) MB, 966.8 / 0.0 ms (average mu = 0.081, current mu = 0.003) allocation failure scavenge might not succeed
[59352:0000023E65B36200] 43644 ms: Mark-sweep 1391.8 (1425.7) -> 1391.4 (1426.2) MB, 952.3 / 0.0 ms (average mu = 0.055, current mu = 0.027) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 000002A7DB3DC5C1]
1: StubFrame [pc: 000002A7DB3A26EE]
Security context: 0x030e7eb1e6e1
2: slice 0000030E7EB06D09
3: /* anonymous /(aka / anonymous */) [000003034251DCC9] [D:\Workspace\business-portal\node_modulestypescript\lib\tsc.js:~33214] pc=000002A7DC4AFFD1
4: argu...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF79DD9ECF5
2: 00007FF79DD781A6
3: 00007FF79DD78BB0
4: 00007FF79E009AAE
5: 00007FF79E0099DF
6: 00007FF79E547724
7: 00007FF79E53DE87
8: 00007FF79E53C3FC
9: 00007FF79E545377
10: 00007FF79E5453F6
11: 00007FF79E0E84B7
12: 00007FF79E18019A
13: 000002A7DB3DC5C1
When I replace the action type of combineReducers to combineReducers
These are my compiler options in tsconfig
"compilerOptions: {
"outDir": "dist",
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"declaration": false,
"noFallthroughCasesInSwitch": true,
"importHelpers": true,
"noEmitHelpers": true,
"noImplicitAny": true,
"skipLibCheck": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"isolatedModules": true,
"allowJs": true,
"checkJs": true,
"module": "es2015",
"noImplicitReturns": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"strict": true,
"pretty": true,
"removeComments": true,
"target": "es5",
"jsx": "react"
}
When I remove two or more declared action(s) that are part of the intersected FormActions type, tsc compiles again.
Related Issues:
How can one reproduce this without knowing the types of your Actions and Reducers?
Also please fix the formatting of the opening post. It's a pain to read.
Apologies for the formatting, I've updated the opening post.
Actions are es6 classes implementing Action from redux
e.g.
export default class ExampleAction implements Action<ActionKeys> {
readonly type = ActionKeys.CreateDeal;
}
and reducers are typed with Reducer from redux
e.g.
```ts
const SampleReducer: Reducer<
SampleState,
SampleActions
= (
state: SampleState= new SampleState(),
action: SampleActions
) => {
// switch statements
return state;
}
But, like, just how many members are in each union you're trying to intersect here?
Each of the intersections have 2~6 action types, 50 total actions included in the total union.
Apologies for not being able to upload the code, I will try get around to creating a sandbox later today.
6^12 is about 2 billion possible alternatives, soooooooooo
50 total actions included in the total union
You've got an intersection listed up there, not a union? Is that intentional?
https://github.com/rebyul/tsmemalloc
Sorry this took so long, I had a deadline due last week and had to chug through without typing my reducers.
The linked repository isn't able to replicate the OOM issue that I am having, and I am unable to invest more time into creating a bigger project to trigger an OOM exception. It is somewhat close to how I have my reducers set up (multiple base level reducers with some nested reducers. The tsc diagnostics looks like this:
I could feel the intellisense getting significantly slower after adding the IFormState interface with reference to the Formik library. I apologize for the lack of information I have provided.
You've got an intersection listed up there, not a union? Is that intentional?
I apologize, it is an intersection; I would have thought it should be a union but the combineReducers function gives compilation errors if its changed to a union.
Also, on my repo that is having the OOM issues, running tsc --diagnostics has the followering values:
There is a related issue on DefinitelyTyped https://github.com/DefinitelyTyped/DefinitelyTyped/issues/35514 which seems to be having similar issues.
Most helpful comment
How can one reproduce this without knowing the types of your Actions and Reducers?
Also please fix the formatting of the opening post. It's a pain to read.