Revert "improve writing performance by avoiding redux for pty events"

This reverts commit 44dfb0faf8.
This commit is contained in:
Guillermo Rauch 2017-09-25 13:55:04 +02:00
parent 56a4ab26bb
commit b775e23c3c
5 changed files with 64 additions and 8 deletions

View file

@ -1,16 +1,19 @@
import rpc from '../rpc';
import isUrl from '../utils/url-command';
import {keys} from '../utils/object';
import findBySession from '../utils/term-groups';
import {
SESSION_ADD,
SESSION_RESIZE,
SESSION_REQUEST,
SESSION_ADD_DATA,
SESSION_PTY_DATA,
SESSION_PTY_EXIT,
SESSION_USER_EXIT,
SESSION_SET_ACTIVE,
SESSION_CLEAR_ACTIVE,
SESSION_USER_DATA,
SESSION_URL_SET,
SESSION_URL_UNSET,
SESSION_SET_XTERM_TITLE
} from '../constants/sessions';
@ -45,10 +48,30 @@ export function requestSession() {
}
export function addSessionData(uid, data) {
return {
type: SESSION_PTY_DATA,
uid,
data
return (dispatch, getState) => {
dispatch({
type: SESSION_ADD_DATA,
data,
effect() {
const session = getState().sessions.sessions[uid];
if (session) {
const enterKey = data.indexOf('\n') > 0;
const url = enterKey ? isUrl(session.shell, data) : null;
if (url) {
return dispatch({
type: SESSION_URL_SET,
uid,
url
});
}
}
dispatch({
type: SESSION_PTY_DATA,
uid,
data
});
}
});
};
}

View file

@ -6,7 +6,6 @@ import {render} from 'react-dom';
import rpc from './rpc';
import init from './actions/index';
import terms from './terms';
import * as config from './utils/config';
import * as plugins from './utils/plugins';
import * as uiActions from './actions/ui';
@ -47,11 +46,28 @@ rpc.on('session add', data => {
// we aggregate all the incoming pty events by raf
// debouncing, to reduce allocation and iterations
let req;
let objects = {};
rpc.on('session data', d => {
// the uid is a uuid v4 so it's 36 chars long
const uid = d.slice(0, 36);
const data = d.slice(36);
terms[uid].term.write(data);
if (objects[uid] === undefined) {
objects[uid] = data;
} else {
objects[uid] += data;
}
if (!req) {
req = requestAnimationFrame(() => {
for (const i in objects) {
if ({}.hasOwnProperty.call(objects, i)) {
store_.dispatch(sessionActions.addSessionData(i, objects[i]));
}
}
objects = {};
req = null;
});
}
});
rpc.on('session data send', ({uid, data, escaped}) => {

View file

@ -4,6 +4,7 @@ import {createLogger} from 'redux-logger';
import rootReducer from '../reducers/index';
import effects from '../utils/effects';
import * as plugins from '../utils/plugins';
import writeMiddleware from './write-middleware';
export default () => {
const logger = createLogger({
@ -12,7 +13,7 @@ export default () => {
});
const enhancer = compose(
applyMiddleware(thunk, plugins.middleware, thunk, effects, logger),
applyMiddleware(thunk, plugins.middleware, thunk, effects, writeMiddleware, logger),
window.devToolsExtension()
);

View file

@ -3,5 +3,7 @@ import thunk from 'redux-thunk';
import rootReducer from '../reducers/index';
import effects from '../utils/effects';
import * as plugins from '../utils/plugins';
import writeMiddleware from './write-middleware';
export default () => createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, effects));
export default () =>
createStore(rootReducer, applyMiddleware(thunk, plugins.middleware, thunk, effects, writeMiddleware));

View file

@ -0,0 +1,14 @@
import terms from '../terms';
// the only side effect we perform from middleware
// is to write to the react term instance directly
// to avoid a performance hit
export default () => next => action => {
if (action.type === 'SESSION_PTY_DATA') {
const term = terms[action.uid];
if (term) {
term.write(action.data);
}
}
next(action);
};