Performance improvement suggestion
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 38/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript
- Área
- performance
Línea de trabajo
Comienza en el punto de entrada diff_core y compara los ajustes propuestos de trimming y callback-index con el comportamiento de diff existente en la biblioteca. Prueba casos de anteposición, adición al final, inserción, eliminación, coincidencia exacta y diff general con arrays grandes; se considera terminado cuando las ediciones simples habituales son más rápidas y los callbacks y resultados siguen siendo correctos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Thanks so much for this library. I've been using a highly modified version for diffing arrays and found for some large array sets with simple edits it was quite slow (eg: 2+ seconds when prepending many items).
For my use case, the edits are often single append, prepend, insert or delete operations and I found for these common cases I could speed up things considerably by trimming common items from the start/end before calling the core diff routine. With this tweak, many operations that previously took 150 - 2000ms now take 1-2 ms.
The code below shows the basic concept. As mentioned, I'm using a modified version of the library with different callbacks that just give the insert and delete operations - but it should be relatively easy to adapt it to work with this library again.
// callback(op, index, count) where op = "insert" or "delete"
export function diff(oldArray, newArray, callback, compareEqual)
{
if (!compareEqual)
compareEqual = function(a,b) { return a == b; }
// Get the min and max length of the two arrays
let minLength = Math.min(oldArray.length, newArray.length);
let maxLength = Math.max(oldArray.length, newArray.length);
// Work out how many matching items at the start
let trimStart = 0;
while (trimStart < minLength &&
compareEqual(oldArray[trimStart], newArray[trimStart]))
{
trimStart++;
}
// Exact match?
if (trimStart == maxLength)
return;
// Simple Append?
if (trimStart == oldArray.length)
{
callback('insert', oldArray.length, newArray.length - oldArray.length);
return;
}
// Work out how many matching items at the end
let trimEnd = 0;
while (trimEnd < (minLength - trimStart) &&
compareEqual(oldArray[oldArray.length - trimEnd - 1], newArray[newArray.length - trimEnd - 1]))
{
trimEnd++;
}
// Simple prepend?
if (trimEnd == oldArray.length)
{
callback('insert', 0, newArray.length - oldArray.length);
return;
}
// Simple insert?
if (trimStart + trimEnd == oldArray.length)
{
callback('insert', trimStart, newArray.length - oldArray.length);
return;
}
// Simple delete?
if (trimStart + trimEnd == newArray.length)
{
callback('delete', trimStart, oldArray.length - newArray.length);
return;
}
// Untrimmed?
if (trimStart == 0 && trimEnd == 0)
{
return diff_core(oldArray, newArray, callback, compareEqual);
}
// Trimmed diff - slice the arrays and adjust the indicies on the callbacks
return diff_core(
oldArray.slice(trimStart, -trimEnd),
newArray.slice(trimStart, -trimEnd),
(op, index, count) => callback(op, index + trimStart, count),
compareEqual
);
}
- Lenguaje dominante
- JavaScript
- Estrellas
- 9.2k
- Forks
- 555
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 5
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de kpdecker/jsdiff
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Migrating to ESM onlyAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
kpdecker/jsdiff#703 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Applying a patch with a fuzzFactor can be very very slowPosiblemente ocupada @json-open-source la tomó hace 39 días. Abiertoperformance
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
kpdecker/jsdiff#692 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 45/100
kpdecker/jsdiff#684 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
reversing a text diff?Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
kpdecker/jsdiff#629 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de kpdecker/jsdiff
Issues similares
-
Edit: Monumental TV [PY]Abiertochannels:edit check:passed
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 94/100
lidofinance/docs#1033 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día