Conversation
|
@Animesh26526 is attempting to deploy a commit to the Kautilya DK's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the scheduling simulator to support optional native C++ execution (via a Node.js addon) with a TypeScript fallback, adds priority-based algorithms plus context-switch overhead, and routes scheduling execution through a server-side API.
Changes:
- Added a native-addon wrapper (
lib/scheduling-native.ts) and C++ implementations/bindings for scheduling algorithms, with TS fallbacks. - Added Priority (preemptive/non-preemptive) algorithms and context switching time (rendered as
CSblocks) and updated metrics calculations. - Updated UI/forms to include
priority, moved scheduling execution toapp/api/schedule, and refreshed docs/build scripts.
Reviewed changes
Copilot reviewed 29 out of 32 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updated feature list, run modes, and native build guidance. |
| package.json | Added node-gyp build/clean scripts and native dev/build modes. |
| lib/FirstComeFirstServe.ts | Re-export algorithm from native wrapper. |
| lib/RoundRobin.ts | Re-export algorithm from native wrapper. |
| lib/ShortestJobFirst.ts | Re-export algorithm from native wrapper. |
| lib/ShortestRemainingTimeFirst.ts | Re-export algorithm from native wrapper. |
| lib/PriorityNonPreemptive.ts | New re-export module for priority non-preemptive. |
| lib/PriorityPreemptive.ts | New re-export module for priority preemptive. |
| lib/scheduling-native.ts | Native addon loader + TS fallback implementations for all algorithms. |
| cpp/include/Process.h | Added C++ Process struct (includes priority). |
| cpp/include/Algorithms.h | Added C++ algorithm function declarations. |
| cpp/src/binding.cc | Added Node/V8 bindings and Process marshaling. |
| cpp/src/FirstComeFirstServe.cpp | Added C++ FCFS implementation. |
| cpp/src/RoundRobin.cpp | Added C++ RR implementation. |
| cpp/src/ShortestJobFirst.cpp | Added C++ SJF implementation. |
| cpp/src/ShortestRemainingTimeFirst.cpp | Added C++ SRTF implementation. |
| cpp/src/PriorityNonPreemptive.cpp | Added C++ priority non-preemptive implementation. |
| cpp/src/PriorityPreemptive.cpp | Added C++ priority preemptive implementation. |
| binding.gyp | Added native build configuration (C++20). |
| app/api/schedule/route.ts | New API route to run algorithms and apply context-switch blocks. |
| components/MainForm.tsx | Added priority/context-switch inputs, new algorithms, and server-side scheduling submission. |
| components/ProcessForm.tsx | Added priority field + validation and numeric inputs. |
| components/GanttChart.tsx | Added CS label support for context-switch blocks. |
| components/SummaryTable.tsx | Reworked CT/WT/TAT calculations using full timeline (idle + CS). |
| components/SummaryStatistics.tsx | Guarded throughput against divide-by-zero; Process type updated. |
| components/footer.tsx | Footer markup removed (now returns nothing). |
| BUILDING.md | Added native build documentation. |
| CPP_SETUP.md | Added VS Code/C++ setup guide. |
| CPP_INTEGRATION.md | Added integration write-up and usage notes. |
| .gitignore | Ignored node-gyp/native build artifacts and IDE files. |
Comments suppressed due to low confidence (1)
components/SummaryTable.tsx:185
- The totals row spans 4 columns, but the table has 6 columns (ID, AT, BT, CT, TAT, WT). As written,
totalWaitingTimerenders under the Turnaround column andtotalTurnaroundTimeunder the Waiting column. Adjust thecolSpan/cell order so totals align with their headers (or include both totals under the correct columns).
<TableRow>
<TableCell colSpan={4} className="pl-3 text-xs">
Total
</TableCell>
<TableCell className="text-center">{totalWaitingTime}</TableCell>
<TableCell className="text-center">{totalTurnaroundTime}</TableCell>
</TableRow>
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import Link from "next/link"; | ||
| import { GitHubLogoIcon } from "@radix-ui/react-icons"; | ||
|
|
||
| export default function Footer() { |
There was a problem hiding this comment.
Footer doesn’t return any JSX/null, so TypeScript will infer this component returns void and it cannot be used as a JSX component (it’s rendered in app/layout.tsx). Return a footer element again (or explicitly return null).
| export default function Footer() { | |
| export default function Footer() { | |
| return null; |
| for (let i = 0; i < sortedProcesses.length; i++) { | ||
| let nextProcess = -1; | ||
| let highestPriority = Infinity; | ||
| let currentTime = 0; | ||
|
|
||
| // Calculate current time based on result | ||
| for (const proc of result) { | ||
| if (proc.process_id !== -1) { | ||
| currentTime += proc.burst_time; | ||
| } | ||
| } | ||
|
|
||
| // Find highest priority process that has arrived | ||
| for (let j = 0; j < sortedProcesses.length; j++) { | ||
| if (!completed[j] && sortedProcesses[j].arrival_time <= currentTime) { | ||
| if (sortedProcesses[j].priority < highestPriority) { | ||
| highestPriority = sortedProcesses[j].priority; | ||
| nextProcess = j; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // If no process available, find next arrival | ||
| if (nextProcess === -1) { | ||
| for (let j = 0; j < sortedProcesses.length; j++) { | ||
| if (!completed[j]) { | ||
| const gapDuration = sortedProcesses[j].arrival_time - currentTime; | ||
| if (gapDuration > 0) { | ||
| result.push({ | ||
| process_id: -1, | ||
| arrival_time: -1, | ||
| burst_time: gapDuration, | ||
| priority: 0, | ||
| background: 'transparent', | ||
| }); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| i = -1; | ||
| continue; | ||
| } | ||
|
|
||
| // Execute the selected process | ||
| const currentProcess = sortedProcesses[nextProcess]; | ||
| result.push(currentProcess); | ||
| completed[nextProcess] = true; | ||
| } |
There was a problem hiding this comment.
The TypeScript fallback for Priority Non-Preemptive has a broken time-advance loop: currentTime is reset to 0 each iteration and recomputed ignoring idle blocks (process_id === -1). This can repeatedly add the same idle gap and restart (i = -1), potentially causing an infinite loop and incorrect schedules. Track currentTime as a single variable that advances by all blocks added to the timeline (including idle), and set each scheduled process slice’s start time consistently (as other algorithms do).
| "build-native": "node-gyp configure && node-gyp build", | ||
| "build-native-safe": "npm run build-native || true", | ||
| "dev": "next dev", | ||
| "build": "next build", | ||
| "dev:native": "npm run build-native-safe && next dev", | ||
| "build:native": "npm run build-native-safe && next build", |
There was a problem hiding this comment.
build-native-safe uses || true, which works in POSIX shells but fails on Windows because true isn’t a command in cmd.exe. Use a cross-platform no-op (e.g., || echo "Native build failed") or a small Node one-liner that exits 0 so dev:native/build:native work on Windows as documented.
| const getInitialContextSwitch = () => { | ||
| const contextSwitch = searchParams?.get("contextSwitch"); | ||
| if (contextSwitch) { | ||
| return parseInt(contextSwitch); |
There was a problem hiding this comment.
getInitialContextSwitch() returns parseInt(contextSwitch) without guarding NaN. If the query param is invalid, this can propagate NaN into the form and eventually into the schedule request (leading to burst_time: NaN context-switch blocks). Prefer const n = Number.parseInt(...); return Number.isNaN(n) ? 0 : n;.
| return parseInt(contextSwitch); | |
| const n = Number.parseInt(contextSwitch, 10); | |
| return Number.isNaN(n) ? 0 : n; |
| - Node.js (v16 or higher) | ||
| - Python 3.10 or higher (required for node-gyp) | ||
| - For Windows: Visual Studio Build Tools with C++ support | ||
| - For macOS: Xcode Command Line Tools | ||
| - For Linux: Build tools (gcc, g++, make) |
There was a problem hiding this comment.
This doc says Node.js v16+ is supported, but the repo is on Next.js 14 (and @types/node 20), which requires a newer Node version. Please align this prerequisite with the actual minimum supported Node version (and keep it consistent with README.md).
| - Build the C++ addon automatically (via `postinstall`) | ||
|
|
There was a problem hiding this comment.
This guide claims npm install will "Build the C++ addon automatically (via postinstall)", but package.json doesn’t define a postinstall script in this PR. Either add the script or update the doc so setup instructions match the repository behavior.
| - Build the C++ addon automatically (via `postinstall`) | |
| It does not automatically build the C++ addon; to build it, run `npm run build-native` (see Step 4). |
| "prebuild": "npm run build-native || true", | ||
| "dev": "npm run build-native && next dev", | ||
| "build": "npm run build-native && next build", |
There was a problem hiding this comment.
The package.json scripts shown here (e.g., prebuild, and dev/build always running build-native) don’t match the actual package.json in this PR (dev is plain next dev, and native build is behind dev:native/build:native). Please update this document to match the current scripts so contributors don’t follow incorrect commands.
| "prebuild": "npm run build-native || true", | |
| "dev": "npm run build-native && next dev", | |
| "build": "npm run build-native && next build", | |
| "dev": "next dev", | |
| "dev:native": "npm run build-native && next dev", | |
| "build": "next build", | |
| "build:native": "npm run build-native && next build", |
| if (typeof window === "undefined") { | ||
| try { | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const { createRequire } = require("module") as { | ||
| createRequire: (filename: string) => NodeRequire; | ||
| }; | ||
| const nativeRequire = createRequire(__filename); | ||
| nativeAddon = nativeRequire("../build/Release/scheduling_algorithms") as NativeAddon; | ||
| } catch { | ||
| console.warn("Native C++ addon not found. Using TypeScript implementations."); | ||
| } |
There was a problem hiding this comment.
Native addon loading uses createRequire(__filename) and then requires ../build/Release/scheduling_algorithms relative to the compiled JS file location. In a Next.js production build, this module is typically bundled/emitted under .next/server/..., so that relative path often won’t point at the project-root build/Release output, causing the native path to never load in production. Consider resolving from process.cwd() (or another stable base) so the addon can be found reliably when it exists.
Done Customizing the Web App as per our Needs